VideoJS volume control handle second player

I'm working on multi-language project with using JS Video player. I would like to ask whether it is possible to link the volume control event from first video player to another player on the site. So when a change occurs of volume in the first player will be an same change transfered to the second player. Thanks for your response. Best regards JS

Upvotes: 0

Views: 5658

Answers (2)

Colin
Colin

Reputation: 1215

const player1 = videojs('video1'), player2 = videojs('videojs2');
player1.on('volumechange', () => {
    player2.volume(player1.volume())
})

volume method to get and set volume

volumechange event

Upvotes: 1

misterben
misterben

Reputation: 7821

There's work currently in progress within video.js to support audio language tracks which would better suit this use case, but a hack for now would be to move the second player's volume control into the first player

var player1 = videojs('video1');
var player2 = videojs('video2');
var p1vol = player1.controlBar.volumeMenuButton;
var p2vol = player2.controlBar.volumeMenuButton;
player1.muted(true);
// Insert player2's volume control before player1's control in player1's control bar
player1.controlBar.addChild(p2vol, {}, player1.controlBar.children().indexOf(p1vol));
// Remove player1's volume control
player1.controlBar.removeChild(p1vol);

Upvotes: 0

Related Questions