I'm using videojs from https://vjs.zencdn.net/5.16.0/video.min.js to embed a video in my page. I have an action to be performed on click of the 'bigplaybutton'.
I tried to get the element by class name vjs-big-play-button(i haven't created a button explicitly...just using the one from videojs) and add an event listener to it.
document.getElementsByClassName("vjs-big-play-button").addEventListener('click', somefunction);
(or)
document.getElementsByClassName("vjs-big-play-button").onclick = function(){
console.log("play");
};
Neither of them work. I'm not sure if my approach is right. Kindly suggest a solution to achieve this.
So I made further research and found a solution which works. But still not sure why getting the element by class name din't work. So here is the solution which worked for me.
var player = videojs("videoElementId");
player.bigPlayButton.on('click', function(){
// do the action
});
If you want to add event on Big Play Button you can use the bellow code :
var previewPlayer = videojs(document.querySelector('.video-js-preview'));
previewPlayer.bigPlayButton.on('click', function () {
// your action here.
});
if you want to add event on video play you can use the below:
previewPlayer.on('play', () => { // your action here. });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With