我想使用javascript更改视频的播放速度。
这是我的html代码:
//Playback Speeds
const playbackSpeed = document.getElementById("speedButtons"); //Add variable to different speed buttons
playbackSpeed.addEventListener("click", changeSpeed);
function changeSpeed() {
myVideo.playbackRate = playbackSpeed.buttons[playbackRate.selectedIndex].value;
}
<div id="Speeds">
<button type="button" id="speedButton">Speed</button>
<div id="speedButtons">
<button value=0.5>0.5x</button>
<button value=0.75>0.75x</button>
<button value=1>1x</button>
<button value=1.25>1.25x</button>
<button value=1.5>1.5x</button>
<button value=1.75>1.75x</button>
<button value=2>2x</button>
</div>
它不起作用。这是我从Chrome浏览器得到的错误:
videoScripts.js:144 Uncaught ReferenceError: playbackRate is not defined
at HTMLDivElement.changeSpeed (videoScripts.js:144)
这就像chrome在谈论的javascript中的144:
playbackSpeed.buttons[playbackRate.selectedIndex].value;