我的duration 无法执行,为什么呢?
来源:3-1 play、pause、duration
慕侠9181480
2019-08-23 16:00:42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<video src="../imooc.mp4" controls id="vid"></video>
<div id="playVid">播放</div>
<div id="stopVid">暂停</div>
<script>
//play 控制视频播放
var videoNode = document.getElementById("vid");
//duration 获取视频长度 (秒)
setTimeout(function(){
console(videoNode.duration)
}, 3000);
playVid.onclick = function(){
videoNode.play()
}
//pause 控制视频暂停
stopVid.onclick = function(){
videoNode.pause()
}
</script>
</body>
</html>
1回答
樱桃小胖子
2019-08-23
打印结果的语句写错了,应该是console.log

同学如果在谷歌浏览器查看打印结果,假如出现了如下报错提示,不要惊慌

这是因为Chrome的自动播放的政策在2018年4月做了更改,
新的行为:浏览器为了提高用户体验,减少数据消耗,现在都在遵循autoplay政策,Chrome的autoplay 政策如下:
(1)muted autoplay始终被允许
(2)音乐的autoplay 只有在下面集中情况下起作用:
①有用户行为发生像(click,tap,etc);
②对于桌面程序,用户已经提前播放了音频;
③对于移动端用户将音频网址home screen;
不过,如果你想让你的chrome浏览器自动播放,可以用以下谷歌提供的办法解决:
在chrome的地址栏中输入:chrome://flags/#autoplay-policy,回车打开设置页面,在该设置改页面会看到黄色方框标记的字体:Autoplay policy ,该选项默认设置为Default,改为:No user gesture is required ,修改选项后页面下方会弹出个提示框,点击提示框上的“RELAUNCH NOW”即可
希望可以帮到你!
相似问题