PhoneGap iOS无法使用HTML 5播放视频 [英] PhoneGap iOS can't play video using HTML 5

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

问题描述

我正在制作phonegap应用,我需要在其中播放视频。我知道为了在Android上播放视频,我需要使用其中一个插件,但要在iOS上播放视频,我可以使用HTML 5视频标签。我有这些代码行:

I'm building phonegap app and I need to play video in it. I know in order to play video on Android, I need to use one of the plugins available, but to play video on iOS, I can use HTML 5 video tag. I have these lines of code:

 <div id="video">
    <video id="video01" width="300" height="300" controls>
        <source src="images/test2.mp4" type="video/mp4" />
    </video>
</div>

我可以看到视频框,但由于某些原因我无法播放视频。在控制台中我没有看到任何错误。

I can see "video box", but I cannot play video for some reason. In console I don't see any errors.

我正在使用的视频来自此页面: http://www.quirksmode.org/html5/tests/video.html

Video I'm using is from this page: http://www.quirksmode.org/html5/tests/video.html

在iPhone Safari中我可以加载MP4版本那个页面没有任何问题。

And in iPhone Safari I can load MP4 version from that page without any problems.

推荐答案

我知道它已经有一段时间了,但我看了一些旧的问题,而且我注意到我完全忘了为我的问题发布解决方案。

I know it has been a while, but I was looking at some of my old questions, and I've noticed that I completely forgot to post solution to my problem.

最后我设法使用Cordova File api修复了问题,解决方案看起来不便。像这样:

In the end I've managed to fix the issue using Cordova File api, and solution looks smth. like this:

 window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
                console.log("gotFS");


                getFolder(fileSystem, "video", function(folder) {
                    filePath = folder.toURL() + "\/" + "videotest.mp4";

                    playVideo(filePath);

                }, function() {
                    console.log("failed to get folder");
                });

            },
            function() {
                console.log("failed to get filesystem");
            });



function playVideo(uri) {


        var player = document.getElementById("videoPlayer");
        var source = document.createElement("source");

        source.src = uri;
        source.type = "video/mp4";

        player.appendChild(source);
        player.load();
    }

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

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