@@ -1063,8 +1063,12 @@ function sepiaFW_build_ui_cards(){
10631063 if ( data . brand == "Spotify" ) {
10641064 var webPlayerDiv = document . createElement ( 'DIV' ) ;
10651065 webPlayerDiv . className = "spotifyWebPlayer cardBodyItem fullWidthItem" ;
1066- var contentUrl = linkUrl . replace ( "spotify:" , "https://open.spotify.com/embed/" ) . replace ( ":play" , "" ) . replace ( / : / g, "/" ) . trim ( ) ;
1067- webPlayerDiv . innerHTML = '<iframe src="' + contentUrl + '" width="100%" height="80" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>' ;
1066+ var contentUrl = "https://" + linkUrl . replace ( "spotify:" , "open.spotify.com/embed/" ) . replace ( ":play" , "" ) . replace ( / : / g, "/" ) . trim ( ) ;
1067+ webPlayerDiv . innerHTML = '<iframe '
1068+ + 'src="' + contentUrl + '" width="100%" height="80" frameborder="0" allowtransparency="true" '
1069+ + 'allow="encrypted-media" '
1070+ + 'sandbox="allow-forms allow-popups allow-same-origin allow-scripts" ' + '>'
1071+ + '</iframe>' ;
10681072 cardBody . appendChild ( webPlayerDiv ) ;
10691073 //Apple Music
10701074 } else if ( data . brand == "Apple Music" ) {
@@ -1087,15 +1091,26 @@ function sepiaFW_build_ui_cards(){
10871091 var f = document . createElement ( 'iframe' ) ;
10881092 f . id = 'youTubeWebPlayer-' + playerId ;
10891093 f . allow = "autoplay; encrypted-media;" ;
1094+ f . sandbox = "allow-same-origin allow-scripts allow-presentation" ;
10901095 f . frameBorder = 0 ;
10911096 f . style . width = "100%" ; f . style . height = "280px" ; f . style . overflow = "hidden" ;
10921097 f . style . border = "4px solid" ; f . style . borderColor = "#212121" ;
10931098 if ( data . autoplay ) {
1099+ //stop all previous audio first
1100+ if ( SepiaFW . client . controls ) {
1101+ SepiaFW . client . controls . media ( {
1102+ action : "stop" ,
1103+ skipFollowUp : true
1104+ } ) ;
1105+ } else {
1106+ SepiaFW . audio . stop ( ) ;
1107+ }
10941108 addYouTubeControls ( f ) ;
10951109 }
10961110 if ( linkUrl . indexOf ( "/embed" ) < 0 ) {
10971111 //convert e.g.: https://www.youtube.com/results?search_query=purple+haze%2C+jimi+hendrix
1098- f . src = "https://www.youtube.com/embed?autoplay=1&enablejsapi=1&playsinline=1&fs=1&listType=search&list=" + linkUrl . replace ( / .* ?s e a r c h _ q u e r y = / , "" ) . trim ( ) ;
1112+ f . src = "https://www.youtube.com/embed?autoplay=1&enablejsapi=1&playsinline=1&iv_load_policy=3&fs=1&listType=search&list="
1113+ + linkUrl . replace ( / .* ?s e a r c h _ q u e r y = / , "" ) . trim ( ) ;
10991114 } else {
11001115 f . src = linkUrl ;
11011116 }
@@ -1630,12 +1645,13 @@ function sepiaFW_build_ui_cards(){
16301645 return footer ;
16311646 }
16321647
1633- //--- YouTube Card Controls ---
1648+ //------ YouTube Card Controls --- ---
16341649
16351650 var youTubeMessageListenerExists = false ;
16361651 var youTubePlayersTriedToStart = { } ;
16371652 var youTubeLastActivePlayerId = undefined ;
16381653 var youTubeLastActivePlayerState = undefined ;
1654+ var youTubePlayConfirmTimer = undefined ;
16391655
16401656 function addYouTubeControls ( frameEle ) {
16411657 frameEle . onload = function ( ) {
@@ -1655,25 +1671,15 @@ function sepiaFW_build_ui_cards(){
16551671 $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'playVideo' } ) , "*" ) ;
16561672 } else if ( data . event == 'infoDelivery' && data . info ) {
16571673 //console.log(JSON.stringify(data));
1658- if ( data . info . playerState != undefined ) youTubeLastActivePlayerState = data . info . playerState ;
1674+ if ( data . info . playerState != undefined ) {
1675+ youTubeLastActivePlayerState = data . info . playerState ;
1676+ }
1677+ youTubeLastActivePlayerId = data . id ;
16591678 if ( data . info . playerState == - 1 ) {
16601679 //Skip if faulty
1661- if ( data . info . availableQualityLevels . length == 0 || data . info . videoBytesTotal == 1 ) {
1662- //console.log(data.info.playlist.length - 1);
1663- //console.log(data.info.playlistIndex);
1664- if ( ! youTubePlayersTriedToStart [ data . id ] && data . info . playlistIndex == 0 ) {
1665- youTubePlayersTriedToStart [ data . id ] = true ;
1666- $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1667- } else if ( data . info . playlist && data . info . playlist . length > 0 ) {
1668- if ( data . info . playlistIndex != undefined && data . info . playlistIndex < ( data . info . playlist . length - 1 ) ) {
1669- //console.log('--- next ---');
1670- $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1671- delete youTubePlayersTriedToStart [ data . id ] ;
1672- }
1673- }
1674- }
1675- } else {
1676- youTubeLastActivePlayerId = data . id ;
1680+ youTubeSkipIfNotPlayed ( data , $player ) ;
1681+ } else if ( data . info . playerState == 1 ) {
1682+ clearTimeout ( youTubePlayConfirmTimer ) ;
16771683 }
16781684 }
16791685 }
@@ -1683,6 +1689,36 @@ function sepiaFW_build_ui_cards(){
16831689 frameEle . contentWindow . postMessage ( JSON . stringify ( { event :'listening' , id : frameEle . id } ) , "*" ) ;
16841690 } ;
16851691 }
1692+ function youTubeSkipIfNotPlayed ( data , $player , skipFirstTest ) {
1693+ if ( skipFirstTest || data . info . availableQualityLevels . length == 0 ) {
1694+ //console.log(data.info.playlist.length - 1);
1695+ //console.log(data.info.playlistIndex);
1696+ if ( ! youTubePlayersTriedToStart [ data . id ] && data . info . playlistIndex == 0 ) {
1697+ youTubePlayersTriedToStart [ data . id ] = true ;
1698+ //console.log('--- next A ---');
1699+ $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1700+ } else if ( data . info . playlist && data . info . playlist . length > 0 ) {
1701+ if ( data . info . playlistIndex != undefined && data . info . playlistIndex < ( data . info . playlist . length - 1 ) ) {
1702+ //console.log('--- next B ---');
1703+ $player [ 0 ] . contentWindow . postMessage ( JSON . stringify ( { event :'command' , func :'nextVideo' } ) , "*" ) ;
1704+ delete youTubePlayersTriedToStart [ data . id ] ;
1705+ }
1706+ }
1707+ } else {
1708+ //confirm play
1709+ youTubeSetConfirmTimer ( data , $player ) ;
1710+ }
1711+ }
1712+ function youTubeSetConfirmTimer ( data , $player ) {
1713+ clearTimeout ( youTubePlayConfirmTimer ) ;
1714+ youTubePlayConfirmTimer = setTimeout ( function ( ) {
1715+ //console.log('--- confirm check ---');
1716+ if ( Cards . youTubePlayerGetState ( ) != 1 ) {
1717+ data . info . playlistIndex ++ ;
1718+ youTubeSkipIfNotPlayed ( data , $player , true ) ;
1719+ }
1720+ } , 3000 ) ;
1721+ }
16861722 Cards . youTubePlayerGetState = function ( ) {
16871723 if ( youTubeLastActivePlayerId ) {
16881724 var $player = $ ( '#' + youTubeLastActivePlayerId ) ;
@@ -1696,6 +1732,7 @@ function sepiaFW_build_ui_cards(){
16961732 }
16971733 }
16981734 Cards . youTubePlayerControls = function ( cmd ) {
1735+ clearTimeout ( youTubePlayConfirmTimer ) ;
16991736 if ( youTubeLastActivePlayerId && youTubeLastActivePlayerState > 0 ) {
17001737 var $player = $ ( '#' + youTubeLastActivePlayerId ) ;
17011738 if ( $player . length == 0 ) {
@@ -1716,4 +1753,4 @@ function sepiaFW_build_ui_cards(){
17161753 }
17171754
17181755 return Cards ;
1719- }
1756+ }
0 commit comments