/* Class to handle You Tube videos. Used by the tag */ ccs.YoutubeVideo = function(playerId) { var self; var playerId; var ytplayer; var played; function constructorFn(playerId) { self = this; this.playerId = playerId; ytplayer = null; played = false; // this bit pollutes the global namespace, but this can't be helped window['onytplayerReady_' + playerId] = function(playerId) { self.onReady(); } window['onytplayerStateChange_' + playerId] = function(state) { self.onStateChange(state); } var oldOnReady = window.onYouTubePlayerReady; window.onYouTubePlayerReady = function(playerId) { if (window['onytplayerReady_' + playerId]) { window['onytplayerReady_' + playerId](playerId); } if (oldOnReady) { oldOnReady(playerId); } } } constructorFn.prototype.onReady = function() { ytplayer = document.getElementById(playerId); ytplayer.addEventListener("onStateChange", "onytplayerStateChange_" + playerId); } constructorFn.prototype.onStateChange = function(newState) { // newState: Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5). // When the SWF is first loaded it will broadcast an unstarted (-1) event. When the video is cued and ready to play // it will broadcast a video cued event (5). if (newState == 1) { if (!played) { played = true; self.onFirstPlay(); } } } // override to do logging, etc. constructorFn.prototype.onFirstPlay = function() { } return new constructorFn(playerId); }