写一个视频播放网页,要求网页可以对视频进度控制,自定义倍数,全屏,音量控制
时间: 2023-06-16 13:05:35 浏览: 223
以下是一个简单的视频播放网页的HTML、CSS和JavaScript代码:
HTML代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>视频播放网页</title>
<style>
video {
width: 800px;
height: 450px;
}
</style>
</head>
<body>
<video id="myVideo" controls>
<source src="myVideo.mp4" type="video/mp4">
<source src="myVideo.ogg" type="video/ogg">
<source src="myVideo.webm" type="video/webm">
Your browser does not support HTML5 video.
</video>
<br>
<button onclick="playPause()">播放/暂停</button>
<button onclick="makeBig()">放大</button>
<button onclick="makeSmall()">缩小</button>
<button onclick="makeNormal()">恢复</button>
<br>
<input type="range" id="volumeBar" min="0" max="1" step="0.1" value="1" onchange="setVolume()">
<button onclick="setSpeed(0.5)">0.5x</button>
<button onclick="setSpeed(1)">1x</button>
<button onclick="setSpeed(1.5)">1.5x</button>
<button onclick="setSpeed(2)">2x</button>
<br>
<button onclick="fullScreen()">全屏</button>
<button onclick="exitFullScreen()">退出全屏</button>
<script>
var video = document.getElementById("myVideo");
function playPause() {
if (video.paused) {
video.play();
} else {
video.pause();
}
}
function makeBig() {
video.width = 1200;
video.height = 675;
}
function makeSmall() {
video.width = 400;
video.height = 225;
}
function makeNormal() {
video.width = 800;
video.height = 450;
}
function setVolume() {
video.volume = document.getElementById("volumeBar").value;
}
function setSpeed(speed) {
video.playbackRate = speed;
}
function fullScreen() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen();
} else if (video.msRequestFullscreen) {
video.msRequestFullscreen();
}
}
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
</script>
</body>
</html>
```
CSS代码:
```
video {
width: 800px;
height: 450px;
}
```
JavaScript代码:
```
var video = document.getElementById("myVideo");
function playPause() {
if (video.paused) {
video.play();
} else {
video.pause();
}
}
function makeBig() {
video.width = 1200;
video.height = 675;
}
function makeSmall() {
video.width = 400;
video.height = 225;
}
function makeNormal() {
video.width = 800;
video.height = 450;
}
function setVolume() {
video.volume = document.getElementById("volumeBar").value;
}
function setSpeed(speed) {
video.playbackRate = speed;
}
function fullScreen() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen();
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen();
} else if (video.msRequestFullscreen) {
video.msRequestFullscreen();
}
}
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
```
该网页包括一个video标签,用于显示视频。该标签带有controls属性,以便用户可以对视频进行控制。
视频的源文件在source标签中指定,可以指定多个源,以便确保浏览器可以在不同的格式中选择最合适的一个。
网页中的按钮和输入框可以让用户对视频进行控制。JavaScript代码包括了一些函数,用于在用户点击按钮或滑动输入框时执行相应的操作,如播放、暂停、调整音量、调整播放速度、全屏等。
注意,全屏功能需要使用不同的API调用,具体取决于浏览器。在这个例子中,我们使用了四种不同的API调用,以便兼容不同的浏览器。
阅读全文