使用 cordova 从 iOS 中的图库播放视频

Play video from gallery in iOS using cordova

您好,我正在使用 Filepicker Plugin 从我的 iOS cordova application 中的图库获取图像和视频。

当我们从图库中选取图像或视频时,我正在从插件中获取图像和视频的临时路径。 我在图片标签中显示了图片,但视频没有播放。看来临时路径will-not played。 是否有获得 actual path for play the video 的解决方案或是否有任何 plugin for iOS to convert temporary path to actual path?

请帮忙..

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

干杯。