Will X
Will X

Reputation: 327

How to initially mute videos?

I have tried:

videojs("cats").ready(function(){
myPlayer.volume(0);
});

... but it did not work. I searched here and through the documents and am not finding the answer, or using the code correctly.

Upvotes: 16

Views: 35905

Answers (7)

7urkm3n
7urkm3n

Reputation: 6311

There'r few ways to set Mute on VideoJS.

 {muted: true} OR this.volume(0) OR "muted" attribute in a video tag

Sample below:

  var setupOpt = {
      'techOrder': ["html5", "flash"],
      'muted'    : true, //OR YOU CAN ADD MUTE Attr.
      'controls' : true,
      'autoplay' : true,
      'preload'  : 'auto',
      'height'   : '500px',
      'width'    : '500px',
      'poster'   : "Url for poster"
  };

  videojs("my-video", setupOpt , function() {
    var player = this;
        player.src({ src: "URL!", type: 'TYPE!'});
        player.volume(0); //Volume range 0.0 to 1 (0.0, 0.1, 0.2 ...)
    // });
  });

Upvotes: 4

The problem in the code is that the myPlayer variable is not defined

videojs("cats", {}, function(){
          var myPlayer = this;
          myPlayer.volume(0);
});

Upvotes: 0

mvmoay
mvmoay

Reputation: 1625

Might be a bit late, but I think the solution is quite easy. Change your code from myPlayer to this. Should look like this:

videojs("cats").ready(function(){
    this.volume(0);
});

This is untested, but it should work, I think. Even if you had a variable myPlayer that takes the player, it will contain it only after having set the .ready() callback, so in the callback, the variable won't be holding your player.

Maybe my explanation is wrong, but you could try this... ;-)

EDIT: Just saw some of the other answers, that should also work.

Upvotes: 0

dannio
dannio

Reputation: 1040

might be a bit late.

In your javascript, try:

myPlayer.muted(true);

Upvotes: 18

Will X
Will X

Reputation: 327

Okay so the answer is easy:

just add: muted to the tag, such as:

 <video id="cats" class="video-js vjs-fullscreen vjs-default-skin" muted autoplay controls loop preload="auto" width="600" height="400"
      data-setup="{}">
    <source src="x.webm" type='video/webm' /> 
  </video>

Upvotes: 15

heff
heff

Reputation: 3239

When you init the player, you can set muted to true.

videojs("cats", { muted: true });

Upvotes: 6

Austin Henley
Austin Henley

Reputation: 4633

Your code myPlayer.volume(0.5); will not mute the video. You need to change that to:

myPlayer.volume(0);

From the documentation: "0 is off (muted), 1.0 is all the way up, 0.5 is half way."

Upvotes: 0

Related Questions