Tuesday, January 17, 2012

[YouTube-API] onStateChange stopped firing !!

Hi

Perfectly working youtube playlist script stopped working suddenly.
The script is supposed to play the following clips one after another.
8ejypIv8zSA
I_izvAbhExY

When the first one finishes 2nd one will start. I had it working.
But I am not sure what happned, it stopped working. Now at the end of
the first clip
it just displays the Replay button. 2nd clip does not start.
I think "onStateChange" is not firing for some reason !!

Please help


Here is my code:
==============================================

<html>

<body bgcolor=ffffff>


<center>


<a name="ytplayer"></a>

<div id="ytplayer_div1">You need Flash player 8+ and JavaScript
enabled to view this video.</div>

<div id="ytplayer_div2"></div>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/swfobject/2/swfobject.js
"></script>


<script type="text/javascript">

// Ready Handler (this function is called automatically by YouTube
JavaScript Player when it is ready)

function onYouTubePlayerReady( playerid )
{
var o = document.getElementById( 'ytplayer_object' );
if ( o )
{
o.addEventListener( "onStateChange", "ytplayer_statechange" );
o.addEventListener( "onError", "ytplayer_error" );
}
}

// This event is fired whenever the player's state changes.
// 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).

function ytplayer_statechange( state )
{
if ( state == 0)
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;
ytplayer_playlazy( 50 );
}
}


function ytplayer_playlazy( delay )
{
if ( typeof ytplayer_playlazy.timeoutid != 'undefined' )
{
window.clearTimeout( ytplayer_playlazy.timeoutid );
}
ytplayer_playlazy.timeoutid = window.setTimeout( ytplayer_play,
delay );
}

function ytplayer_play( )
{

var item = ytplayer_playlist[ ytplayer_playitem ];
cap = item;

var o = document.getElementById( 'ytplayer_object' );
if ( o )
{
o.loadVideoById( ytplayer_playlist[ ytplayer_playitem ] );
}
}


function ytplayer_error( error )
{
if ( error )
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;

ytplayer_playlazy( 5000 );

}
}

function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}

// MAINLINE
================================================================


var ytplayer_playlist = [ ];
var ytplayer_playitem = 0;


ytplayer_playlist.push( '8ejypIv8zSA' );
ytplayer_playlist.push( 'I_izvAbhExY' );


swfobject.addLoadEvent( ytplayer_render_player );


// Render Youtube Player
------------------------------------------------------------

function ytplayer_render_player( )
{


swfobject.embedSWF
(

'http://www.youtube.com/v/' +
ytplayer_playlist[ ytplayer_playitem ] +
'&enablejsapi=1&rel=0&fs=1&start=1&autoplay=1',
'ytplayer_div1',
'600',
'488',
'8',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer_object'
}
);

}


</script>

</center>

</html>


==============================================

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment