javascript - HTML 5 video player external control - Stack Overflow

I'm using html5 video player to play some videos and trying to use external controls with javascri

I'm using html5 video player to play some videos and trying to use external controls with javascript. manage to get the player play and pause. but i cannot get it to mute and unmute using the buttons.
if someone can help with this matter its highly appropriated.

Here is the HTML code

<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 Code

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);  

  }

}

Thanks in advance.

I'm using html5 video player to play some videos and trying to use external controls with javascript. manage to get the player play and pause. but i cannot get it to mute and unmute using the buttons.
if someone can help with this matter its highly appropriated.

Here is the HTML code

<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 Code

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);  

  }

}

Thanks in advance.

Share Improve this question edited Jul 12, 2013 at 6:47 AndroidLearner 4,6945 gold badges35 silver badges67 bronze badges asked Jul 12, 2013 at 6:40 maxlkmaxlk 1,0576 gold badges18 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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>

Try this:

var videoObject = document.getElementById('myMovie');
videoObject.muted = !videoObject.muted;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745350226a4623788.html

相关推荐

  • javascript - HTML 5 video player external control - Stack Overflow

    I'm using html5 video player to play some videos and trying to use external controls with javascri

    10小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信