Something like (additions highlighted):
Code:
<script>
// Script by jscheuer1. Works in Firefox, Chrome, IE 8 and up, Opera. Page must be live in order for the script to work with IE.
var controllable_player,
statechange = function(e){
if(e.data === 0){alert('Video Ended');}
};
function onYouTubeIframeAPIReady() {
controllable_player = new YT.Player('controllable_player');
new YT.Player('controllable_player', {events: {'onStateChange': statechange}}).setVolume(100);
}
if(window.opera){
addEventListener('load', onYouTubeIframeAPIReady, false);
}
</script>
But you have two new YT.Player() calls. I'm not sure why or if in fact you really need both of them or how they would be combined, or if you need both which or if both should get the events object assigned to it.
But maybe:
Code:
<script>
// Script by jscheuer1. Works in Firefox, Chrome, IE 8 and up, Opera. Page must be live in order for the script to work with IE.
var controllable_player,
statechange = function(e){
if(e.data === 0){alert('Video Ended');}
};
function onYouTubeIframeAPIReady() {
controllable_player = new YT.Player('controllable_player', {events: {'onStateChange': statechange}});
controllable_player.setVolume(100);
}
if(window.opera){
addEventListener('load', onYouTubeIframeAPIReady, false);
}
</script>
See also:
https://developers.google.com/youtub..._api_reference
Oh, and I seem to recall that the only reliable cross browser onStateChange is believed to be 1, for play. But things may have improved since then.
Bookmarks