找到你要的答案

Q:Play video from gallery in iOS using cordova

Q:从iOS应用科尔多瓦画廊播放视频

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

我用filepicker插件在我的iOS应用从科尔多瓦画廊获得的图像和视频。

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?

请帮助..

answer1: 回答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.

我也有同样的问题。您所拥有的临时路径是应用程序缓存文件夹的URL。我在我的应用程序上解决这个问题,通过保存本地选择的文件,然后使用所得到的路径。

我用下面的代码来解决这个问题。

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) { }

干杯.

ios  cordova  video  filepicker.io