Reputation: 9
The website EndlessVideo used to work fine, but all of a sudden it will not loop videos anymore. I've found that running the following code in the console has the wanted effect, but strangely, adding it to the bottom of the page does not seem to work:
<script>
ytplayer = jQuery("#ytapiplayer")[0];
ytplayer.addEventListener("onStateChange", "onytplayerStateChange1");
function onytplayerStateChange1(state){console.log(state);if(state == 0){ytplayer.playVideo();}}
</script>
I've tried various modifications of the above, including calling it from onYouTubePlayerReady()
, running it on a timer, etc... Nothing seems to work.
Upvotes: 0
Views: 919
Reputation: 728
The looping is enabled by passing the &loop=1
query string.
The JavaScript API isn't needed to enable looping.
Upvotes: 0
Reputation: 11916
The youtube video player loads after the page is loaded. So the event is not actually getting bound to the player. Please try adding the state handler after the video starts playing or at least when the player has loaded.
Upvotes: 1