<!DOCTYPE html>
<html>
<body>
<video id="myVideo" width="320" height="240" controls>
<source src="/i/photo/shanghai.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<p>请通过单击按钮或调整右下角的音量来更改音量。</p>
<button onclick="setHalfVolume()" type="button">将音量设置为 0.2</button>
<button onclick="setFullVolume()" type="button">将音量设置为 1.0</button>
<p id="demo"></p>
<script>
var x = document.getElementById("myVideo");
x.addEventListener("volumechange", getVolume);
function getVolume() {
document.getElementById("demo").innerHTML = "The audio volume is: " + x.volume;
}
function setHalfVolume() {
x.volume = 0.2;
}
function setFullVolume() {
x.volume = 1.0;
}
</script>
</body>
</html>