android - Samsung S4 (Android 4.4.2) 上 WebView 中的 HTML5 视频问题

标签 android html video cordova

我在 Samsung S4 + Android 4.4.2 上的 Phonegap 3.3 应用中播放视频标签中嵌入的视频时遇到奇怪的问题。

我有以下 HTML 代码:

<video id='myvideo' autoplay=1 preload='auto'></video>

视频通过 Javascript(使用 jQuery)启动:

$('#myvideo').attr('src', 'http://...jpg');
$('#myvideo').attr('poster', 'http://...mp4');

$('#myvideo')[0].play();

视频未按预期开始。

从 Android 4.2 升级到 Android 4.4.2 后,该问题才出现。其他运行 Android 4.4.2 的智能手机(例如 Nexus 4、5)上不存在此问题。

最佳答案

将此设置添加到您的 WebView 设置

webSettings.setMediaPlaybackRequiresUserGesture(false);

这是我的js代码,用于自动播放视频并循环播放(如果您只想播放一次,可以删除这部分

// here is my code to find my video tag
var myVideo = document.getElementsByTagName('video')[0];

// if there is a video tag found ( this js is in a separate js files ) we play the video
if (typeof myVideo !== "undefined")
{
    // setInterval allow me to monitor every 40 millisecond if the video is ending or not, if true we loop the video and play it again
    setInterval(function() {


        if ( myVideo.readyState != 0)
        {
            if (myVideo.paused) {
                myVideo.currentTime = 0;
                myVideo.play();
            }
        }            
    }, 40)
}

关于android - Samsung S4 (Android 4.4.2) 上 WebView 中的 HTML5 视频问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23348396/

相关文章:

android - 如何结合使用 android 的 "openvpn connect"应用程序和 Intent 以编程方式连接和断开 vpn 连接?

java - ListView 未使用按钮更新

javascript - 为什么将值返回到innerHTML 时,函数内部的innerHTML 会被忽略?

css - 主 div 不包含其他 div

jquery - 如何停止选项卡中的视频?

video - FFMPEG 在编码时是否支持用户数据段注入(inject)?

android - IBeacon Android 中的 "If two apps register ranges with the same id, they clobber eachother"是什么意思

java - 崩溃正在尝试寻找视野

javascript - Draggable 同时拖动两个元素

php - Facebook 广告 API PHP : Video upload using AdVideo class