flash - autoplay youtube video -
i have site , in home page have embedded youtube video, div containing player hidden(display:none), so, when button(video) clicked, hide content of page , show youtube player, works ok, love when button(video) clicked, player shows , start reproduce video automatically, i've faild in each attempt, i'm using code find in other web , made changes
swfobject.addloadevent( ytplayer_render_player ); function ytplayer_render_player( ) { swfobject.embedswf ( 'http://www.youtube.com/v/' + youtube_uhma.home + '&enablejsapi=1&rel=0&fs=1&playerapiid=ytplayer', 'ytplayer_div1', '425', '344', '8', null, null, { allowscriptaccess: 'always', allowfullscreen: 'true' }, { id: 'ytplayer_object' } ); } function onyoutubeplayerready( playerid ) { var o = document.getelementbyid( 'ytplayer_object' ); if ( o ) { o.addeventlistener( "onstatechange", "ytplayer_statechange" ); o.addeventlistener( "onerror", "ytplayer_error" ); } } function ytplayer_statechange( state ) { if ( state == 0 ) { ytplayer_playlazy( 5000 ); } } function ytplayer_error( error ) { if ( error ) { ytplayer_playlazy( 5000 ); } } 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 o = document.getelementbyid( 'ytplayer_object' ); if ( o ) { o.loadvideobyid( youtube_uhma.home ); } }
i've post entire code i'm using, so, how can make autoplay here, can see web in action here uhma
all
well, after reading api reference of youtube javascript player , coding while, worked me:
in ytplayer_statechange function, changed validation of state
if ( state == 5 ) //5 means ready play { ytplayer_playlazy( 1000 ); }
the video started play after 1 sec. don't know if best way enough me.
Comments
Post a Comment