I try to create a delegated menu for youtube video and video based audio files in one of my projects webpages and all works fine in FF, Safari, IE and so on, except in Chrome.
I know there are limitations for autoplay in chrome browser since Version 66. (https://developers.google.com/web/updates/2017/09/autoplay-policy-changes)
I came up with the conclusion, that this might be the issue here and verified it by playing mute, what is an exception in chromes autoplay policy.
An user initiated play works fine even in chrome. So what I want to try is a delegation of the user action (click an extern play button) to the iframes video to make it accept the play.
var player = YT.Player( ... )
var player_elem = $(iframe#youtube_x);
/* ... */
case "play":
// why mute?
// => https://developers.google.com/youtube/iframe_api_reference?hl=de#Autoplay_and_scripted_playback
// => https://stackguides.com/questions/50507985/youtube-iframe-api-auto-play-not-working-for-chrome-and-video-resolution-set-not
player.mute();
pauseAll(); // 4all player as p => p.pauseVideo()
player.playVideo();
setTimeout(function(){
player.unMute();
setTimeout(function(){
state = player.getPlayerState();
switch(state){
case 5: // positioning
case -1: // not started
case 0: // ended
case 2: // paused
Console.log("cant play content ...");
// player_elem.delegat() is deprecated
player_elem.on( 'click', null, event.data )
break;
case 3: // buffering
Notice.console.log("still buffering .. ");
case 1: // played
break;
}
}, 300);
delayedPlayerStateChanged(player_elem.attr("id"), ctrl_bar);
}, 100);
delayedPlayerStateChanged(player_elem.attr("id"), ctrl_bar);
break;
I need a snippet to delegate the the user action 'play' from my page to get accepted by the iframe as user action. Is this even possible in chrome?