javascript - How can I play two Youtube videos without linking to a playlist? -
i'm new javascript. i'm embedding youtube iframe here: http://www.heartlandpokertour.com/indexbeta.php
using documentation: http://code.google.com/apis/youtube/iframe_api_reference.html
i second video play, looped, after first 1 finished. i'm unable set specific video parameters if try , link/set video id youtube playlist.
i'm assuming need setup event listener , function trigger when yt.playerstate.ended (or 0) broadcast, no idea how this.
update: here current code i'm using player:
<script> // 2. code loads iframe player api code asynchronously. var tag = document.createelement('script'); tag.src = "http://www.youtube.com/player_api"; var firstscripttag = document.getelementsbytagname('script')[0]; firstscripttag.parentnode.insertbefore(tag, firstscripttag); // 3. function creates <iframe> (and youtube player) // after api code downloads. var player; function onyoutubeplayerapiready() { player = new yt.player('player', { height: '258', width: '406', videoid: 'mstqnzmq5pk', playervars: { 'autoplay': 0, 'rel': 0, 'showinfo': 0, 'egm': 0, 'showsearch': 0, }, events: { 'onstatechange': onplayerstatechange, } }); } // 4. api call function when video player ready. function onplayerstatechange(event) { if (event.data == yt.playerstate.ended) { player.stopvideo(); player.videoid = 'c5dtllk5_x8'; player.playvideo(); } } </script>
in first code listing on api website, event might you:
function onplayerstatechange(event) { if (event.data == yt.playerstate.playing && !done) { settimeout(stopvideo, 6000); done = true; } }
you change (not tested i'm afraid):
function onplayerstatechange(event) { if (event.data == yt.playerstate.ended) { player.stopvideo(); player.videoid = 'some id'; player.playvideo(); } }
this logical in opinion, again i'm not sure whether different videos can played within 1 player instance. i've never come across scenario i'm afraid.
edit: try creating new instance of player. you'd create new player, play second video:
function onplayerstatechange(event) { if (event.data == yt.playerstate.ended) { player.stopvideo(); player = new yt.player('player', { height: '258', width: '406', videoid: 'some id', playervars: { 'autoplay': 0, 'rel': 0, 'showinfo': 0, 'egm': 0, 'showsearch': 0, }, events: { //'onstatechange': onplayerstatechange, // not add line because again create new player after second has stopped guess! } }); player.playvideo(); } }
Comments
Post a Comment