使用Cordova在iOS中播放图库中的视频 [英] Play video from gallery in iOS using cordova

查看:257
本文介绍了使用Cordova在iOS中播放图库中的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hi am using Filepicker Plugin for get images and videos from gallery in my iOS cordova application.

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

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?

请帮助.

推荐答案

我也遇到了同样的问题.您拥有的临时路径是应用程序缓存文件夹的URL.我通过保存本地选择的文件并在其后使用生成的路径,在我的应用程序上解决了此问题.

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

干杯.

这篇关于使用Cordova在iOS中播放图库中的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆