Assuming you’re using the Video.js player, this should run when a video starts playing
jQuery(document).ready( function() {
if ( typeof videojs != "undefined" ) {
jQuery.each( videojs.getPlayers(), function() {
this.on('play', function() {
//add your JS function here
});
});
}
});
I just realized that code also assumes that jQuery is loaded on the page, which isn’t necessarily true if you don’t have a video on the page. You might want to check for jQuery too.
if ( typeof jQuery != "undefined" ) {
jQuery(document).ready( function() {
if ( typeof videojs != "undefined" ) {
jQuery.each( videojs.getPlayers(), function() {
this.on('play', function() {
//add your JS function here
});
});
}
});
}
Hi Kyle, the Chrome console is giving me the following error:
“(index):423 Uncaught TypeError: videojs.getPlayers is not a function”
I tried to put it in the head and then after the video. Both gave me the same results. Any sugestions?
Thanks, Pavel.
That works for me in the header and the footer of the page. Are you using Video.js as your player? Are you running the latest version of the plugin? Have you modified the script I posted at all? Did you enclose it in <script> tags?
Hi, yes, I am using the Video.js option and I have plugin version 4.6.7. You can see it here http://www.rakovinaprostaty.org/lekce-vzor/.
Thanks!
Kyle, I have tested it also here: http://jakna.org/. It is simple testing page, no tons of other code like the previous example. You can still see the error.
Thanks, Pavel.
I wasn’t able to look at the video at http://www.rakovinaprostaty.org/lekce-vzor/ because I never got a registration confirmation email, but the video at http://jakna.org/ doesn’t have that error in Chrome, Safari, or Firefox.
Kyle, I have cleared the Chrome cache and it works fine. So sorry about that. Sent you some donation money.
Have a nice day!
Pavel.