无法在iOS 9与Phonegap应用程序播放本地视频 [英] Can't play local videos in IOS 9 with Phonegap app

查看:170
本文介绍了无法在iOS 9与Phonegap应用程序播放本地视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Phonegap 6.2.0做了一个IOS 9应用程序。我需要播放没有连接的视频,所以我下载它使用cordova FileTransfer插件:

I made an IOS 9 app using Phonegap 6.2.0. I need to play videos with no connection, so I download it using cordova FileTransfer plugin:

        var uri = encodeURI(file.url);
        var fileTransfer = new FileTransfer();
        // var fileLocation = cordova.file.applicationStorageDirectory +
        //     '/Documents/' + file.folder + '/' + file.fileName;

        var fileLocation = cordova.file.dataDirectory + file.fileName;

        var deferred = $q.defer();
        fileTransfer.headers = {
            Connection: "close"
        };

        fileTransfer.download(uri, fileLocation, function(result) {
            console.log("Fichero descargado: " + JSON.stringify(result));
            deferred.resolve(result);
        }, function(error) {
            deferred.reject(error);
        });
        return deferred.promise;

我尝试过不同的档案位置下载( https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

I've tried different file locations to download it (https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/)

然后,我使用resolveLocalFileSystemURL返回文件路径:

Then, I return the file path using resolveLocalFileSystemURL:

var deferred = $q.defer();

    var nativePath = cordova.file.dataDirectory + nombreFichero + "." + extension;

    resolveLocalFileSystemURL(nativePath, function(entry) {
        //deferred.resolve(entry.nativeURL);
        console.log("Fichero native: " + entry.toNativeURL());
        console.log("Fichero fullPath: " + entry.fullPath);
        console.log("Fichero toUrl: " + entry.toURL());
        console.log("Fichero toInternalURL: " + entry.toInternalURL());

        deferred.resolve(entry.toURL());
    }, function(error) {
        console.log("Error al leer el fichero: " + JSON.stringify(error));
        deferred.reject(error);
    });
    return deferred.promise;

我已尝试所有文件格式,但都没有工作:

I've tried all file formats but none of them worked:

cdvfile://localhost/library-nosync/97a7d50f-05d1-4642-96e9-b0b26ea41897.mp4

cdvfile://localhost/library-nosync/97a7d50f-05d1-4642-96e9-b0b26ea41897.mp4

file:/// var /移动/容器/数据/应用程序/ 6CD24D7A-7A39-4AFE-A43B-788FCDFCEB5A / Library / NoCloud / a88d38b8-85e8-4b9b-b57e-a8eb2731eb0d.mp4

file:///var/mobile/Containers/Data/Application/6CD24D7A-7A39-4AFE-A43B-788FCDFCEB5A/Library/NoCloud/a88d38b8-85e8-4b9b-b57e-a8eb2731eb0d.mp4

http:// localhost / library-nosync / 97a7d50f-05d1-4642-96e9-b0b26ea41897 .mp4 和使用端口12344

http://localhost/library-nosync/97a7d50f-05d1-4642-96e9-b0b26ea41897.mp4 and using port 12344

某些格式无效,有些显示按钮播放删除...

Some formats do nothing, some show the button play strikethrough...

在所有的答案,我已经阅读他们建议使用.toNativeUrl(),但它不适合我...

In all answers I had read they recommend to use .toNativeUrl() but it doesn't work for me...

我也试过cordova插件-streaming-media(我不能发布更多链接),但它不工作(没有播放视频,没有错误...)

I also tried cordova-plugin-streaming-media (I can't post more links), but it does not work (no play video, no errors...)

任何想法? p>

Any idea?

推荐答案

解决。

我的代码运行正常,并且播放视频。问题是在下载视频的URL中,它获取一个字符串与url,而不是视频(因此下载和打开文件方法不会抛出错误)

My code works good and play videos. The problem was in the URL to download the video, it gets a string with the url and not the video (therefore download and open file method didin't throw error)

总结一下,toUrl()的工作原理。

Summarizing, toUrl() works.

感谢@Gandhi的回复。

Thanks @Gandhi for your replies.

这篇关于无法在iOS 9与Phonegap应用程序播放本地视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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