Loading video failed on html5 phonegap

前端 未结 3 2087
我在风中等你
我在风中等你 2020-12-18 09:20

I want to show local videos by HTML5 video tag on phonegap android What is wrong with this html code?:

3条回答
  •  时光取名叫无心
    2020-12-18 10:04

    Create a folder for your application and save the video there. Lets say APP_FOLDER_ is the desired name for that folder; APPLICATION_WORKING_DIR_ is the global reference to root directory and vid is the name of the video:

    /*code to create the app's folder*/
    var onFileSystemRequestSuccess = function(fs) {
        //success fn create dir
        var onDirCreateSuccess = function(dir) {
            //fs instance pointing to root dir
            APPLICATION_WORKING_DIR_ = dir;
        };
        //fail fn
        var onDirCreateFail = function(err) {
            //manage error
        };
        fs.root.getDirectory(APP_FOLDER_, { create: true, exclusive: false }, onDirCreateSuccess, onDirCreateFail);
    };
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemRequestSuccess, function () { });
    

    Then, just point src of video tag to:

    /*code to set src of video tag*/
    //additional: check if APPLICATION_WORKING_DIR_.fullpath ends with "/" and create the path to video
    var str_path = (APPLICATION_WORKING_DIR_.fullPath.toString().endsWith('/') ? APPLICATION_WORKING_DIR_.fullPath : APPLICATION_WORKING_DIR_.fullPath + '/') + vid;
    document.getElementById('video_tag_name').src = str_path;
    

    Finally, clicking in the element will begin playing.

    Hope this helps.

提交回复
热议问题