javascript - About Use YouTube Player API loadPlaylist -
how use loadplaylist
option next video played automatically? code this, won't work, can't play video:
<div id="player"></div> <script> var tag = document.createelement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstscripttag = document.getelementsbytagname('script')[0]; firstscripttag.parentnode.insertbefore(tag, firstscripttag); var player; function onyoutubeiframeapiready() { player = new yt.player('player', { height: '390', width: '640', loadplaylist:{ listtype:'playlist', list:['4ivdp8kj_0u','4mjrs-clozu'], index:parseint(0), suggestedquality:'small' }, events: { 'onready': onplayerready, 'onstatechange': onplayerstatechange } }); } function onplayerready(event) { event.target.playvideo(); } var done = false; function onplayerstatechange(event) { if (event.data == yt.playerstate.playing && !done) { // settimeout(stopvideo, 60000); done = true; } } function stopvideo() { player.stopvideo(); } </script>
i want achieve effect of example: http://www.youtube.com/watch?v=0ddconbbrvq&list=rd02_vty8ftr1vy
thanks much.
i running issue yesterday actually. first of all, in onplayerready
function, need calling loadplaylist
since cue playlist , start playing it.
however, issue running using object syntax when calling playlist made of array of video ids, error. after googling, found stack overflow question suggested using argument syntax , seemed fix it. see differences here: https://developers.google.com/youtube/js_api_reference#playlist_queueing_functions
i took code , changed onplayerready
use loadplaylist
function argument syntax , works. see jsfiddle here: http://jsfiddle.net/rustybailey/9kfyx/
Comments
Post a Comment