0

我正在使用 html5 视频播放器播放一些视频并尝试使用带有javascript. 设法让播放器播放和暂停。但我无法使用按钮使其静音和取消静音。
如果有人可以帮助解决这个问题,那是非常合适的。

这是HTML代码

<video id="myMovie" width="600" height="600" loop preload="auto" video poster="img.jpg" controls>
  <source src="my-video-file.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

<button id="playButton">Play</button>
<button id="volButton">Mute</button>

JavaScript 代码

function playMymovie() {

    var element = document.getElementById('myMovie');

    var element = document.getElementById('pbutton');

    playButton.addEventListener('click', PlayOrPause, false);

    volButton.addEventListener('click', VolMute, false);

}

function PlayOrPause() {
    if(!myMovie.paused && !myMovie.ended) {

        myMovie.pause();

}else{

    myMovie.play()

}

}

function VolMute(){
  if(!myMovie.muted){

     myMovie.muted(true);

  }else{

    myMovie.muted(false);  

  }

}

提前致谢。

4

2 回答 2

4
<html> 
<body> 

<div style="text-align:center"> 

 <button onclick="playPause()">Play/Pause</button> 
<button onclick="muteUnMute()">Mute/UnMute</button> 
     <br> 
<video id="video1" width="420">
 <source src="mov_bbb.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
 Your browser does not support HTML5 video.
</video>
</div> 


<script> 
var myVideo=document.getElementById("video1"); 

function playPause()
{ 
    if (myVideo.paused) 
    myVideo.play(); 
else 
 myVideo.pause(); 
} 

function muteUnMute()
{ 
    if( !myVideo.muted)
 myVideo.muted='muted';
else

myVideo.muted=false;
} 


</script> 

</body> 
</html>
于 2013-07-12T07:36:56.790 回答
0

尝试这个:

var videoObject = document.getElementById('myMovie');
videoObject.muted = !videoObject.muted;
于 2013-07-12T07:02:06.753 回答