使用cordova从iOS中的画廊播放视频

时间:2015-06-23 16:59:13

标签: ios cordova video filepicker.io

您正在使用Filepicker PluginiOS cordova application中的图库中获取图片和视频。

当我们从图库中选择图片或视频时,我会从插件中获取图像和视频的临时路径。 我在图片标签中显示了图片,但视频没有播放。似乎临时路径不会播放。 是否有获取actual path for play the video的解决方案或是否有任何plugin for iOS to convert temporary path to actual path

请帮助..

1 个答案:

答案 0 :(得分:2)

我也有同样的问题。您拥有的临时路径是应用程序缓存文件夹的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) { }

干杯。

相关问题