Check remaining time with Youtube Javascript API -
Check remaining time with Youtube Javascript API -
i embedding youtube video , using yt js api. user encouraged utilize chromecast view embedded video. however, when video cast button in player, player.getcurrenttime()
, player.getplayerstate()
become frozen, , onstatechange
event doesn't fire.
is there can work around these issues, or problem youtube can fix? thanks!
my code:
var player; function onyoutubeiframeapiready() { player = new yt.player('ytplayer', { events:{ 'onstatechange': onplayerstatechange } }); } function onplayerstatechange(event){ console.log('player statechange: '+event.data); //this never runs when casting video. }
here's code
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; //execute player api code downloads function onyoutubeiframeapiready() { player = new yt.player('player', { height: '390', width: '640', videoid: 'm7lc1uvf-ve', events: { 'onready': onplayerready, 'onstatechange': onplayerstatechange } }); } // execute when onready event fires //starts video function onplayerready(event) { console.log("onplayerready"); console.log(event); var duration = event.target.getduration(); console.log("duration:" + duration); fillplaybackrates(); } // when onstatechange event fires function onplayerstatechange(event) { console.log("onplayerstatechange") console.log(event) if (event.data == yt.playerstate.playing) { console.log(yt); } } var pause = $("#pause"), start = $("#start"), mute = $("#mute"); pause.on('click', function () { player.pausevideo(); }); start.on('click', function () { player.playvideo(); }); var fillplaybackrates = function () { var playbackdropdownmenu = $(".dropdown-menu"); var playbackrates = player.getavailableplaybackrates(); console.log(playbackrates); (var = 0; < playbackrates.length; i++) { playbackdropdownmenu.append('<li role="presentation"><a role="menuitem" tabindex="-1" href="#">' + playbackrates[i] + '</a></li>'); } } var playbackratesbutton = $("#playback-rates"); $(document).on('click','.dropdown-menu > li > a', function () { var alternative = $(this).text(); playbackratesbutton.text(option); player.setplaybackrate(option); });
here's total gist: iframeyoutubeapi.html
you can have here: continuing chromecast: embedding youtube custom receivers
javascript youtube chromecast youtube-javascript-api
Comments
Post a Comment