Volume Control

Product(s)
Brightcove Player
Video Cloud
Role(s)
Player Developer
Topic(s)
Audio

In this topic, you will learn how to use two methods, muted() and volume(), to programmatically control audio for Brightcove Player. Of course you can manually control audio using the volume button in the player controls.

volume() method

The volume() method acts as both a getter and a setter depending upon if an argument is passed. If the method is used as a setter, the argument is a decimal number between 0 (muted) and 1.0 (full volume). The argument is a percentage represented as a decimal number.

Below is a code example programmatically using the volume() method to set the volume to 60%.

  videojs('myPlayerID').ready(function(){
    var myPlayer = this;
    myPlayer.volume(.6);
  });

muted() method

The muted() method acts as both a getter and setter depending upon if an argument is passed. If the method is used as a setter, the argument is a boolean value, true to mute and false to unmute.

Below is a code example programmatically using the muted() method to mute player audio.

  videojs('myPlayerID').ready(function(){
    var myPlayer = this;
    myPlayer.muted(true);
  });

volumechange event

If you wish to react to a change in volume you can use the volumechange event. You can set the event listener as follows:

    myPlayer.on('volumechange', function( evt ){
      console.log('event: ', evt);
    })