Play video from gallery in iOS using cordova
Asked Answered
F

1

0

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..

Freezing answered 23/6, 2015 at 16:59 Comment(0)
M
2

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.

Mislike answered 24/6, 2015 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.