Search code examples
javascriptjqueryvideo.js

Is there any support in video.js to set callbacks to have video players in remote browsers mimic an user action?


I am using video.js video player.

I am having an application that is loaded in multiple browsers. The application has a video.js video player loaded in it. One of the app serves as the master or the controller app. The others are controlled apps.

Using websockets I want to send control messages from the master player to the controlled players.

I want the following actions mimicked in the controlled player from the master player:

  1. Volume control.
  2. Play button
  3. Pause button
  4. Skip to any point in the video

Are there callbacks provided when a user initiates these controls in the player? If so, is there sufficient data passed to the callback so that this data can, in turn, through websockets, be passed to a remote player to perform the same action?

Any pointers will be helpful.


Solution

  • Yes, you can try listening to these events from videojs player: volumechange, play, pause, seeked,

    Your code will look like something like this:

    this.player.on("volumechange", (e) => forwardEventToWebSocket(e));
    

    Documentation of all events is available here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#events