[html][js]视频倍速播放功能

时间:2024-03-07 06:56:38

代码

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
	<video id="video" src="t_1234567.mp4" width=50% autobuffer controls type="video/mp4"></video>
	<p>选择播放速率:<select id="selRate">
		<option value="0.5">0.5</option>
		<option value="1" selected>1.0</option>
		<option value="1.25">1.25</option>
		<option value="1.5">1.5</option>
		<option value="2">2.0</option>
		<option value="5">5.0</option>
	</select></p>
	<p><button id="btnPlay">视频播放</button></p>
	  <script>
		var eleSelect = document.getElementById(\'selRate\');
		var eleButton = document.getElementById(\'btnPlay\');
		// 视频元素
		var video = document.getElementById(\'video\');
		// 改变播放速率
		eleSelect.addEventListener(\'change\', function () {
			video.playbackRate = this.value;
		});
		// 点击播放按钮
		eleButton.addEventListener(\'click\', function () {
			video.pause();
		});
	</script>
 </body>
</html>