@@ -1668,7 +1668,9 @@ function sepiaFW_build_ui_cards(){
16681668 return ;
16691669 }
16701670 if ( data . event == 'onReady' ) {
1671- $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'playVideo' } ) , "*" ) ;
1671+ setTimeout ( function ( ) {
1672+ $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'playVideo' } ) , "*" ) ;
1673+ } , 1000 ) ;
16721674 } else if ( data . event == 'infoDelivery' && data . info ) {
16731675 //console.log(JSON.stringify(data));
16741676 if ( data . info . playerState != undefined ) {
@@ -1679,6 +1681,7 @@ function sepiaFW_build_ui_cards(){
16791681 //Skip if faulty
16801682 youTubeSkipIfNotPlayed ( data , $player ) ;
16811683 } else if ( data . info . playerState == 1 ) {
1684+ clearTimeout ( youtubeSkipTimer ) ;
16821685 clearTimeout ( youTubePlayConfirmTimer ) ;
16831686 }
16841687 }
@@ -1689,23 +1692,31 @@ function sepiaFW_build_ui_cards(){
16891692 frameEle . contentWindow . postMessage ( JSON . stringify ( { event :'listening' , id : frameEle . id } ) , "*" ) ;
16901693 } ;
16911694 }
1695+ var youtubeSkipTimer = undefined ;
16921696 function youTubeSkipIfNotPlayed ( data , $player , skipFirstTest ) {
16931697 if ( skipFirstTest || data . info . availableQualityLevels . length == 0 ) {
16941698 //console.log(data.info.playlist.length - 1);
16951699 //console.log(data.info.playlistIndex);
16961700 if ( ! youTubePlayersTriedToStart [ data . id ] && data . info . playlistIndex == 0 ) {
16971701 youTubePlayersTriedToStart [ data . id ] = true ;
16981702 //console.log('--- next A ---');
1699- $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1703+ clearTimeout ( youtubeSkipTimer ) ;
1704+ youtubeSkipTimer = setTimeout ( function ( ) {
1705+ $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1706+ } , 1000 ) ;
17001707 } else if ( data . info . playlist && data . info . playlist . length > 0 ) {
17011708 if ( data . info . playlistIndex != undefined && data . info . playlistIndex < ( data . info . playlist . length - 1 ) ) {
17021709 //console.log('--- next B ---');
1703- $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1710+ clearTimeout ( youtubeSkipTimer ) ;
1711+ youtubeSkipTimer = setTimeout ( function ( ) {
1712+ $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1713+ } , 1000 ) ;
17041714 delete youTubePlayersTriedToStart [ data . id ] ;
17051715 }
17061716 }
17071717 } else {
17081718 //confirm play
1719+ clearTimeout ( youtubeSkipTimer ) ;
17091720 youTubeSetConfirmTimer ( data , $player ) ;
17101721 }
17111722 }
0 commit comments