Play video from gallery in iOS using cordova

681 views Asked by At

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

There are 1 answers

0
Deepu Varghese On BEST ANSWER

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.