-
AuthorPosts
-
February 24, 2015 at 5:07 am #401172
I’ve got this script in my functions.php but it doesn’t work.
add_action('wp_footer', 'ava_current_menu'); function ava_current_menu(){ if(is_page('home')) { ?> <!-- **teera --> <!-- <script async src="https://www.youtube.com/iframe_api"></script> --> <script> var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var ytplayer; function onYouTubeIframeAPIReady() { ytplayer = new YT.Player('vid', { events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); console.log('yt_api working'); } function onPlayerReady(event){ console.log('playeready'); return null; } function onPlayerStateChange(event) { console.log('yt_change'); video_stop(); return null; } function video_stop(){ var q = document.getElementsByTagName("video"); var i; for (i = 0; i < q.length; i++){ q[i].pause(); console.log('videostop'); } }; jQuery('a').click(function(){ console.log('aclick'); video_stop(); ytplayer.pauseVideo(); }); </script> <?php }}
This section
var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
Came straight off youtube iframe_api_reference and is supposed to load the iframe api code asynchronously.
If I replace it with <script async src=”https://www.youtube.com/iframe_api”></script>
The script will load properly most times, but not always (just keep hitting refresh). But still you have browsers that do not support async and the script still doesn’t always load. In the times it does load, it still has problems with onStateChange not triggering when I play the video.
This script works when written for simple HTML page but isn’t working with enfold reliably for some reason.
Thanks,
Teera- This topic was modified 9 years, 8 months ago by teeramusic.
February 24, 2015 at 5:50 pm #401560Hi teeramusic!
Not sure about that. It’s kind of bordering on custom work though.
Are you just trying to display youtube videos? We have a video shortcode.
Best regards,
ElliottFebruary 25, 2015 at 10:40 am #401943I agree, it’s kind of bordering on custom work, but at the same time, if it works on a regular HTML page it should also work in Enfold unless Enfold has done something quirky with the script?
I’m trying to stop all the other videos automatically except for the one that is playing so that there can only be one video playing at any given moment.
Thanks,
TeeraFebruary 26, 2015 at 5:36 pm #402827Hey!
I haven’t played around with the video APIs that much but you can see where we interact with it in /enfold/js/shortcodes.js on lines 647 – 1141.
It should only be creating players on these elements though,
$('.avia-slideshow iframe[src*="youtube.com"], .av_youtube_frame, .avia-slideshow iframe[src*="vimeo.com"], .avia-slideshow video').aviaVideoApi({}, 'li');
Cheers!
ElliottFebruary 27, 2015 at 5:58 am #403173I’ll have a look :)
-
AuthorPosts
- The topic ‘Event watches not firing reliably / scripts not loading.’ is closed to new replies.