Buscar este blog

Aviso

El autor de éste blog no se hace responsable de los posibles daños o perdidas de información, que pudieran ocasionarse en su sistema o su vida por la aplicación de la información aquí contenida.

lunes, 10 de junio de 2024

Sync video and audio of two videos in different tabs or windows of browser in the same page

Put this in the video with subtitles in Spanish

/**
* Put this in the video with subtitles in Spanish
*/

var broadCast = new BroadcastChannel('video-sync-player');

var video = document.getElementById("player0");

video.onplay = () => {
console.log("Played video");
broadCast.postMessage({
type: 'video-played',
});
}

video.onpause = () => {
console.log("Paused video");
broadCast.postMessage({
type: 'video-paused',
});
}

Put this in the video with audio in English

/**
* Put this in the video with audio in English
*/

var broadCast = new BroadcastChannel('video-sync-player');

var video = document.getElementById("player0");

broadCast.onmessage = ({ data = {} }) => {
console.log("onmessage video-sync-player: ", data);
if (data.type === 'video-played') {
video.play();
} else if (data.type === 'video-paused') {
video.pause();
} else {
console.log("Yo need to map this event: ", data);
}
};

Thank you!

Más populares

Archivo del blog