我创建了一个简单的HTML文件,以便了解如何使用HTML5添加视频。我在youtube上遵循了一条旧指令,但我找不到解决方案。所有代码都有效,直到我添加全屏
我在哪里犯了错误?我尝试了不同的拼写,大写字母和Mozilla网站的建议,这个论坛以及搜索引擎可以指出的任何其他顶级结果。
以下是代码
<html>
<head>
<style type ="text/css">
div#video_box{width:600px; background:black; margin:0px auto;}
div#video_control{ background:black; padding:10px; opacity:50%;}
input#soundslider{ width:80px}
</style>
<script>
var vid, playbutton, seekbar, seekslider, curtimetext, durtimetext, soundslider, fullscreenbutton;
function initializePlayer() {
vid = document.getElementById("mi_vid");
playbutton = document.getElementById("playpausebutton");
seekslider = document.getElementById("seekslider");
curtimetext = document.getElementById("curtimetext");
durtimetext = document.getElementById("durtimetext");
soundslider = document.getElementById("soundslider");
fullscreenbutton = document.getElementByID("fullscreenbutton");
// event listeners
playbutton.addEventListener("click",playPause,false);
seekslider.addEventListener("change",vidSeek,false);
vid.addEventListener("timeupdate",seektimeupdate,false);
soundslider.addEventListener("change",setvolume,false);
fullscreenbutton.addEventListener("click",toggleFullScreen,false);
}
window.onload= initializePlayer;
function playPause() {
if(vid.paused){
vid.play();
playbutton.innerHTML = "Pause";
}
else {
vid.pause();
playbutton.innerHTML = "Play";
}
}
function vidSeek() {
var seekto = vid.duration * (seekslider.value / 100);
vid.currentTime = seekto;
}
function seektimeupdate() {
var nt = vid.currentTime * (100 /vid.duration);
seekslider.value = nt;
var curmins = Math.floor(vid.currentTime /60);
var cursecs = Math.floor(vid.currentTime - curmins *60);
var durmins = Math.floor(vid.duration /60);
var dursecs = Math.round(vid.duration - durmins *60);
if(cursecs <10) {
cursecs = "0"+cursecs;
}
if(dursecs <10) {
dursecs = "0"+dursecs;
}
curtimetext.innerHTML = curmins+":"+cursecs;
durtimetext.innerHTML = durmins+":"+dursecs;
}
function setvolume() {
vid.volume = soundslider.value /100;
}
function toggleFullScreen() {
if (vid.requestFullScreen){
vid.requestFullscreen();
}
else if (vid.mozRequestFullScreen) {
vid.mozRequestFullScreen();
}
else if (vid.mozRequestFullScreen) {
vid.mozRequestFullscreen();
}
else if (vid.webkitRequestFullscreen) {
vid.webkitRequestFullscreen();
}
else if (vid.msRequestFullscreen) {
vid.msRequestFullscreen();
}
}
</script>
</head>
<body>
<div id="video_box">
<video id="mi_vid" controls="controls" width="600" height="370"><source src="/home/nomouseisdead/video.mp4">
</video>
<div id="video_control">
<button id="playpausebutton">Pause</button>
<button id="fullscreenbutton">full</button>
<input id="seekslider" type="range" min="0" max="100" value="0" step="1">
<span id="curtimetext"></span>/<span id="durtimetext"></span>
<input id="soundslider" type="range" min="0" max="100" value="100" step="1">
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
在你的javascript控制台中看到,你有一个错字。
fullscreenbutton = document.getElementByID("fullscreenbutton");
应该是:
fullscreenbutton = document.getElementById("fullscreenbutton");
也许,这就是问题所在。