代码示例:(标识:event_onratechange)
<!DOCTYPE html>
<html>
<body>
<p>在本例中,我们为 video 元素分配了 "onratechange" 事件。playbackRate 属性用于更改视频的播放速度。</p>
<video id="myVideo" width="320" height="240" autoplay controls onratechange="myFunction()">
<source src="/static/demo/video/shanghai.mp4" type="video/mp4">
Your browser does not support the video tag.
</video><br>
<button onclick="setPlaySpeed()" type="button">设置视频以慢动作播放</button>
<script>
// 获取 id="myVideo" 的 video 元素
var x = document.getElementById("myVideo");
// 将视频的当前播放速度设置为 0.3(慢动作)
function setPlaySpeed() {
x.playbackRate = 0.3;
}
// 当视频播放速度改变时提示一些文字
function myFunction() {
alert("The playing speed of the video was changed");
}
</script>
</body>
</html>