Video.js: Tell whether the video was paused via script or via the player's controls

Created on 20 Feb 2017  路  10Comments  路  Source: videojs/video.js

Description

I would like to know when the user pauses the video via the player.
There is a 'pause' event, but it's also triggered when I call player.pause().
I saw no difference in the events produced in both cases.

It would be nice if player.pause() accepted a parameter that would appear in the resulting event.

Additional Information

I use videojs-youtube, if that's of any concern.
This feature would be equally useful for the 'play' event.

pinned

All 10 comments

馃憤 I'd like to know that as well.
Currently I'm relying on click events for player.controlBar.playToggle.on('click') which is not ideal.

you may try this.on('pause', function(event) { event

@kavin-90 either you didn't complete the sentence or...

@mikeys it seems your were unable to understand so here is an example

var player =  videojs('my-video', {
    playbackRates: [0.5, 1, 1.5, 2]
    }, function () {

    this.on('pause', function(event) {
        alert("Paused");
    });

});

@kavin-90 I'm aware of the pause event but does it contain data wether the event was triggered by 'click' or by something else?

I'm currently using the following

  let pauseHandler = player.on('pause', () => {
    if (!player.waiting) { clearHandlers() }
  })

this code will tell on what time pause trigger

var time = this.currentTime();

@kavin-90 and?

@kavin-90: You may want to read the description more carefully, because your comments fail to address the issue at all.

@mikeys: Nice to see I'm not the only one needing this.
Your workaround is indeed less than ideal, because clicking the toggle button is not the only way to play/pause: other ways include clicking the video itself or pressing space.

This works. In this.onUserInteraction, I set a boolean and do whatever other operations are required:

let controlBar = document.getElementsByClassName('vjs-control-bar')[0],
     controlElements = controlBar.childNodes;
if(controlElements && controlElements.length > 0){
     for(let i=0; i < controlElements.length; i++){
          // get user interaction
          controlElements[i].addEventListener('click', (event) => { this.onUserInteraction(event) });
     }
}

I am in the same situation as you. I used jQuery and it works on me:

I wished in the vent there was some type that tells you if the event is triggered from User-Interaction or from custom code.

$('.vjs-play-control').on('click', function (e) {
    console.log('Play/Pause button clicked.')
});

It might not ideal but this is the best idea that I have right now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0xsven picture 0xsven  路  3Comments

TheKassaK picture TheKassaK  路  3Comments

askaliuk picture askaliuk  路  3Comments

zhulduz picture zhulduz  路  3Comments

stephanedemotte picture stephanedemotte  路  4Comments