video.js icon indicating copy to clipboard operation
video.js copied to clipboard

Tell whether the video was paused via script or via the player's controls

Open hu9o opened this issue 9 years ago • 10 comments

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.

hu9o avatar Feb 20 '17 15:02 hu9o

👍 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.

mikeys avatar Mar 13 '17 10:03 mikeys

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

kavin-90 avatar Mar 13 '17 10:03 kavin-90

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

mikeys avatar Mar 13 '17 12:03 mikeys

@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 avatar Mar 13 '17 13:03 kavin-90

@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() }
  })

mikeys avatar Mar 13 '17 13:03 mikeys

this code will tell on what time pause trigger

var time = this.currentTime();

kavin-90 avatar Mar 13 '17 15:03 kavin-90

@kavin-90 and?

mikeys avatar Mar 14 '17 10:03 mikeys

@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.

hu9o avatar Mar 14 '17 13:03 hu9o

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) });
     }
}

MrWiLofDoom avatar Jun 21 '18 13:06 MrWiLofDoom

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.

aldo-o avatar Mar 20 '19 04:03 aldo-o