Hi,
I use JWPLayer 7.8.4 for playing a HLS stream with DVR functionality
I'd like to run custom code at 2 cases:
1)
The player is not set to autoplay, so if viewer loads the page, he has to push play button to start playing. When he pushes play button, then I want to run my custom code.
2)
For any reason the player may go to 'paused' or 'stopped' state. If the viewer pushes play button in these states, my custom code should run again.
I found, that the best jwplayer event for this is on('play'). It is working find, but unfortunatelly the 'play' event fires when the viewer seeks in the live stream. I do not want to run my code then. Unfortunatelly the 'play' event returns the same object, when the viewer first clicks on play or seeks in stream. The only difference is the position on the seekbar.
So I did this:
jwplayerInstance.on('play', function(e) {
if ( ( playerInstance.getPosition() == '0' && e.oldstate == 'buffering' ) || e.oldstate == 'paused' ){
console.log('Here is the custom code!');
}
});
When the playing started first or the player was in stopped state, then the position is 0 and oldstate is 'buffering', so my code will run.
When the player was in 'paused' state before play button was clicked, then oldstate is 'paused', so my code will run.
When viewer is seeking, the position is not 0 and oldstate is 'buffering', so my code will NOT run.
Fortunatelly, if the viewer seeks, the position will never be 0 again, even if he seeks back to live position.
I don't know if I am right and if this is working as I expected.
And I don't know if this is the best way to achieve this.
Thanks for any help.
↧