我在 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/