Play video from gallery in iOS using cordova

不问归期 提交于 2019-12-25 02:48:12

问题


Hi am using Filepicker Plugin for get images and videos from gallery in my iOS cordova application.

Am getting a temporary path of image and video from the plugin when we pick image or video from the gallery. I displayed the image in the image tag but video is not playing. It seems the temporary path will-not played. Is there any solution for getting actual path for play the video or is there any plugin for iOS to convert temporary path to actual path?

Please help..


回答1:


I also had the same issue. The temporary path that you have is the url to the application cache folder. I solved this issue on my app by saving the file selected locally and using the resultant path thereafter.

I use the following code to solve this.

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, failrequestFileSystem);

function gotFS(fileSystem) {
    fileSystem.root.getDirectory("vids", {create: true}, gotDir);
}

function gotDir(dirEntry) {
    dirEntry.getFile("video.MOV", {create: true, exclusive: false}, gotFile);
}

function gotFile(fileEntry) {
    var localPath = fileEntry.fullPath;
    var localUrl = fileEntry.toURL();

    var fileTransfer = new FileTransfer();
    var uri = encodeURI(<temp path that u have>);
    fileTransfer.download(
        uri,
        localUrl,
        function(entry) {
            uralToUse = entry.nativeURL; // use this url to play video
            var videoNode = document.querySelector('video');
            videoNode.src = entry.toNativeURL();
        },
        function(error) { }
    );
}

function failrequestFileSystem(error) { }

Cheers.



来源:https://stackoverflow.com/questions/31008984/play-video-from-gallery-in-ios-using-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!