HTML5 Video: canPlayType() 在 safari 中不起作用
HTML5 Video: canPlayType() is not working in safari
我尝试了以下代码,但 developer.apple.com 但它抛出错误说:
TypeError:"undefined"不是一个函数(评估'myVideo.canPlayType(myTypes[i]('(
<!doctype html>
<html>
<head>
<title>JavaScript Fallback</title>
<script type="text/javascript">
function checkPlaylist() {
var playAny = 0;
myTypes = new Array ("video/mp4","video/ogg","video/divx");
var nonePlayable = "Your browser cannot play these movie types."
var myVideo = document.getElementsByTagName('video')[0];
for (var i = 0, len = myTypes.length; i < len; x++) {
var canPlay = myVideo.canPlayType(myTypes[i]);
if ((canPlay == "maybe") || (canPlay == "probably"))
playAny = 1;
}
if (playAny == 0)
document.getElementById("video-player").innerHTML = nonePlayable;
}
</script>
</head>
<body onload="checkPlaylist()" >
<div id="video-player" align=center>
<video controls height="200" width="400">
<source src="myMovie.m4v" type="video/mp4">
<source src="myMovie.oga" type="video/ogg">
<source src="myMovie.dvx" type="video/divx">
</video>
</div>
</body>
</html>
使用以下脚本在 Safari 浏览器中检查您的 myType 数组参数:
<!DOCTYPE html>
<html>
<body>
<p>Can my browser play DIVX videos? <span>
<button onclick="supportType(event,'video/divx','H.264')" type="button">Test</button>
</span></p>
<p>Can my browser play MP4 videos? <span>
<button onclick="supportType(event,'video/mp4','avc1.42E01E, mp4a.40.2')" type="button">Test</button>
</span></p>
<p>Can my browser play OGG videos? <span>
<button onclick="supportType(event,'video/ogg','theora, vorbis')" type="button">Test</button>
</span></p>
<script>
function supportType(e,vidType,codType) {
var vid = document.createElement('video');
isSupp = vid.canPlayType(vidType+';codecs="'+codType+'"');
if (isSupp == "") {
isSupp = "No";
}
e.target.parentNode.innerHTML = "Answer: " + isSupp;
}
</script>
</body>
</html>
你在 Safari for Windows 中吗?如果是这样,那可能会失败。Apple 不再支持 Safari for Windows。
你也有var i = 0, len = myTypes.length; i < len; x++
.最后一个x
应该是i
。
相关文章:
- window.open(url).print()在Safari中不起作用
- 复制到剪贴板在safari-angularjs中不起作用
- Javascript Cookies在Safari中不起作用
- 带有Safari的Javascript;不起作用——所有其他浏览器都起作用
- 导航到新url时,Javascript在Safari中不起作用
- JS代码使IE9和Safari冻结,在Opera中不起作用
- html视频javascript播放方法在移动Safari中不起作用
- 为什么这个排序功能在 Safari 中不起作用
- $.getJSON 在 Chrome 和 Safari 中不起作用
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 滚动到顶部按钮在 chrome 或 safari 中不起作用
- jQuery .play() 在移动 Safari 上不起作用
- jQuery .focus() 在 Safari(桌面)的搜索字段中不起作用
- HTML5<视频>元素在Firefox、Opera和Safari中不起作用
- 为什么find('input:focus')在safari中不起作用
- OfflineAudioContext.startRendering()基于承诺的函数在safari中不起作用
- ng模式验证在safari中不起作用
- 图像预览在Safari中不起作用
- 脚本在safari中不起作用
- CreateContextualFragment在safari中不起作用