Wal*_*nes 6 javascript video html5 html5-video ios9
我有一个基本的HTML5视频播放器没有像这样的控件...
<video id="videoPlayer" preload="auto" webkit-playsinline>
<source id="videoSourceMP4" src="" type="video/mp4" />
<source id="videoSourceOGG" src="" type="video/ogg" />
</video>
Run Code Online (Sandbox Code Playgroud)
顶部有一个按钮,按下后会加载所需的视频:
document.getElementById("videoSourceMP4").src = "videos/video.mp4";
document.getElementById("videoSourceOGG").src = "videos/video.ogg";
document.getElementById("videoPlayer").load();
Run Code Online (Sandbox Code Playgroud)
我现在也开始检查视频是否可以播放并且应该开始使用:
document.getElementById("videoPlayer").oncanplaythrough = function(){
document.getElementById("videoPlayer").play();
}
Run Code Online (Sandbox Code Playgroud)
这在ios8中有效,但是自从ios9没有任何反应.视频卡在第一帧上,无法播放.即使我在play()上添加另一个按钮,也没有任何反应.我必须启用控件并使用提供的播放按钮播放它.如果我暂停视频,然后按我自己的播放按钮,它将工作.我希望能够使用我自己设计的控件.
有谁知道为什么现在这样做?
下面的代码的工作原理如下;
视频文件来自http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<style>
video{
width:400px;
border: 2px dashed black;
}
button{
font-size:2em;
padding:1em;
}
</style>
</head>
<body onload='init()'>
<video id="videoPlayer" preload="auto" webkit-playsinline>
<source id="videoSourceMP4" src="" type="video/mp4" />
<source id="videoSourceOGG" src="" type="video/ogg" />
</video>
<br/>
<button type='button' onclick='go()'>Play</button>
<script>
function init(){
document.getElementById("videoPlayer").oncanplaythrough = function(){
document.getElementById("videoPlayer").play();
}
}
function go(){
document.getElementById("videoSourceMP4").src = "small.mp4";
document.getElementById("videoSourceOGG").src = "small.ogg";
document.getElementById("videoPlayer").load();
}
</script>
</body>
Run Code Online (Sandbox Code Playgroud)