Skip to content

Commit ebe0f34

Browse files
committed
youtube web-player beta; allowWebPlayer hidden btn; skin tweaks;
1 parent 4f5717f commit ebe0f34

File tree

8 files changed

+86
-21
lines changed

8 files changed

+86
-21
lines changed

www/css/sepiaFW-skin-canary-dark.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ html {
133133
background: #040404;
134134
max-width: none;
135135
}
136-
#sepiaFW-chat-controls-more-menu button {
136+
#sepiaFW-chat-controls-more-menu button,
137+
.sepiaFW-touch-device #sepiaFW-chat-controls-more-menu button:hover {
137138
background: #F4F4F4;
138139
color: #040404;
139140
}

www/css/sepiaFW-skin-neo-sepia-dark.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ html {
116116
background: #101418;
117117
max-width: none;
118118
}
119-
#sepiaFW-chat-controls-more-menu button {
119+
#sepiaFW-chat-controls-more-menu button,
120+
.sepiaFW-touch-device #sepiaFW-chat-controls-more-menu button:hover {
120121
background: #beff1a;
121122
color: #101418;
122123
}

www/css/sepiaFW-skin-spot.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ html {
130130
background: #111111;
131131
max-width: none;
132132
}
133-
#sepiaFW-chat-controls-more-menu button {
133+
#sepiaFW-chat-controls-more-menu button,
134+
.sepiaFW-touch-device #sepiaFW-chat-controls-more-menu button:hover {
134135
background: #F4F4F4;
135136
color: #111111;
136137
}

www/scripts/sepiaFW.android.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function sepiaFW_build_android(){
1818
"spotify_link": {name: "Spotify URI", package: "com.spotify.music"},
1919
"apple_music": {name: "Apple Music App", package: "com.apple.android.music"},
2020
"apple_music_link": {name: "Apple Music URI", package: "com.apple.android.music"},
21-
"amazon_music": {name: "Amazon Music", package: "com.amazon.mp3"},
22-
"soundcloud": {name: "SoundCloud", package: "com.soundcloud.android"},
23-
"deezer": {name: "Deezer", package: "deezer.android.app"},
21+
//"amazon_music": {name: "Amazon Music", package: "com.amazon.mp3"},
22+
//"soundcloud": {name: "SoundCloud", package: "com.soundcloud.android"},
23+
//"deezer": {name: "Deezer", package: "deezer.android.app"},
2424
"vlc_media_player": {name: "VLC", package: "org.videolan.vlc"}
2525
}
2626
Android.musicAppsThatBehaveByPackage = {

www/scripts/sepiaFW.client.controls.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,14 @@ function sepiaFW_build_client_controls(){
193193
SepiaFW.audio.stop(SepiaFW.audio.getMusicPlayer());
194194
}
195195

196+
//Embedded Player
197+
if (SepiaFW.ui.cards.allowWebPlayer || controlData.service.indexOf("_embedded") > 0){
198+
//just skip, cards will do the rest...
199+
//YouTube
200+
//if (controlData.service.indexOf("youtube") == 0){}
201+
196202
//Android Intent music search
197-
if (SepiaFW.ui.isAndroid && (!controlData.service || controlData.service.indexOf("_link") == -1)){
203+
}else if (SepiaFW.ui.isAndroid && (!controlData.service || controlData.service.indexOf("_link") == -1)){
198204
var allowSpecificService = true;
199205
SepiaFW.android.startMusicSearchActivity(controlData, allowSpecificService, function(err){
200206
//error callback

www/scripts/sepiaFW.ui.actions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ function sepiaFW_build_ui_actions(){
164164
|| (url.indexOf('http') !== 0 && !!url.match(/^\w+:/)) //TODO: keep an eye on this! Does it prevent some cool URL scheme features?
165165
|| url.indexOf('https://maps.') === 0 || url.indexOf('http://maps.') === 0
166166
|| url.indexOf('https://www.google.com/maps/') === 0 || url.indexOf('https://www.google.de/maps/') === 0
167-
|| url.indexOf('https://itunes.apple.com/') === 0
167+
|| url.indexOf('https://itunes.apple.com/') === 0 || url.indexOf('https://music.apple.com/') === 0 || url.indexOf('https://geo.itunes.apple.com/') === 0
168+
|| url.indexOf('https://open.spotify.com/') === 0
168169
){
169170
cordova.InAppBrowser.open(url, '_system');
170171
}else{
@@ -175,7 +176,7 @@ function sepiaFW_build_ui_actions(){
175176
var newWindow = window.open(url, '_blank');
176177
newWindow.opener = null;
177178
//some special links that should not leave an empty browser tab
178-
if (url.indexOf('spotify:') == 0){
179+
if (url.indexOf('spotify:') == 0 || url.indexOf('itmss:') == 0 || url.indexOf('musics:') == 0){
179180
setTimeout(function(){
180181
newWindow.close(); //NOTE: problem here is that app-request dissapears before user interaction if not already allowed by user
181182
}, 500);

www/scripts/sepiaFW.ui.build.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ function sepiaFW_build_ui_build(){
541541
+ "<span>" + "CLEXI ID" + ": </span>"
542542
+ "<input id='sepiaFW-menu-clexi-server-id' type='url' spellcheck='false'>"
543543
+ "</li>"
544-
+ "<li id='sepiaFW-menu-select-music-app-li' title='Select default music app for search intents.'><span>Default music app: </span></li>"
544+
+ "<li id='sepiaFW-menu-select-music-app-li' title='Select default music app for search intents.'>"
545+
+ "<span>Default music app: </span></li>"
546+
//+ "<span id='sepiaFW-menu-toggle-music-cards-btn'><i class='material-icons'>art_track</i></span>"
545547
+ "<li id='sepiaFW-menu-administration-li'>"
546548
+ "<button id='sepiaFW-menu-ui-dataprivacy-btn'>" + SepiaFW.local.g('data_privacy') + "</button>"
547549
+ "<button id='sepiaFW-menu-ui-license-btn'>" + SepiaFW.local.g('license') + "</button>"
@@ -772,6 +774,19 @@ function sepiaFW_build_ui_build(){
772774

773775
//Music app selector
774776
document.getElementById('sepiaFW-menu-select-music-app-li').appendChild(Build.musicAppSelector(SepiaFW.config.getMusicAppCollection()));
777+
SepiaFW.ui.onShortLongPress($('#sepiaFW-menu-select-music-app-li').find('span').first()[0], function(){
778+
//Short press
779+
}, function(){
780+
//Long press
781+
if (SepiaFW.ui.cards.allowWebPlayer){
782+
SepiaFW.ui.cards.allowWebPlayer = false;
783+
SepiaFW.ui.showPopup("Music Cards deactivated");
784+
}else{
785+
SepiaFW.ui.cards.allowWebPlayer = true;
786+
SepiaFW.ui.showPopup("Music Cards activated (for debugging)");
787+
}
788+
}, true);
789+
//$('#sepiaFW-menu-toggle-music-cards-btn').off().on('click', function(){});
775790

776791
//Wake-word stuff - Hey SEPIA
777792
if (!SepiaFW.wakeTriggers){

www/scripts/sepiaFW.ui.cards.js

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ function sepiaFW_build_ui_cards(){
989989
//LINK
990990

991991
var currentLinkItemId = 0;
992+
var youTubeMessageListenerExists = false;
992993

993994
function buildLinkElement(cardElementInfo){
994995
var newId = ("sepiaFW-card-id-" + Cards.currentCardId++);
@@ -1035,28 +1036,67 @@ function sepiaFW_build_ui_cards(){
10351036
//linkCardEle.setAttribute('data-element', JSON.stringify(cardElementInfo));
10361037
cardBody.appendChild(linkCardEle);
10371038

1038-
//Experimenting with Spotify Web Player
1039-
if (!SepiaFW.ui.isMobile && data.type && data.type == "musicSearch" && data.brand == "Spotify" && linkUrl){
1040-
if (Cards.allowWebPlayer){
1039+
//Experimenting with web players
1040+
if (Cards.allowWebPlayer || data.embedded){
1041+
//Spotify
1042+
if (data.type && data.type == "musicSearch" && data.brand == "Spotify" && linkUrl){
10411043
var webPlayerDiv = document.createElement('DIV');
1042-
webPlayerDiv.className = "spotifyWebPlayer cardBodyItem fullWidthItem"
1043-
var contentUrl = "https://" + linkUrl.replace("spotify:", "open.spotify.com/embed/").replace(":play", "").replace(/:/g, "/").trim();
1044+
webPlayerDiv.className = "spotifyWebPlayer cardBodyItem fullWidthItem";
1045+
var contentUrl = linkUrl.replace("spotify:", "https://open.spotify.com/embed/").replace(":play", "").replace(/:/g, "/").trim();
10441046
webPlayerDiv.innerHTML = '<iframe src="' + contentUrl + '" width="100%" height="80" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>';
10451047
cardBody.appendChild(webPlayerDiv);
1046-
}
1047-
}else if (!SepiaFW.ui.isMobile && data.type && data.type == "musicSearch" && data.brand == "Apple Music" && linkUrl){
1048-
if (Cards.allowWebPlayer){
1048+
//Apple Music
1049+
}else if (data.type && data.type == "musicSearch" && data.brand == "Apple Music" && linkUrl){
10491050
var webPlayerDiv = document.createElement('DIV');
1050-
webPlayerDiv.className = "appleMusicWebPlayer cardBodyItem fullWidthItem"
1051+
webPlayerDiv.className = "appleMusicWebPlayer cardBodyItem fullWidthItem";
10511052
webPlayerDiv.innerHTML = '<iframe '
10521053
+ 'allow="autoplay *; encrypted-media *;" frameborder="0" height="150" '
10531054
+ 'style="width:100%;max-width:660px;overflow:hidden;background:transparent;" '
10541055
+ 'sandbox="allow-forms allow-popups allow-same-origin allow-scripts '
10551056
+ ((SepiaFW.ui.isSafari)? 'allow-storage-access-by-user-activation' : '')
10561057
+ ' allow-top-navigation-by-user-activation" '
1057-
+ 'src="' + linkUrl.replace("itunes.", "embed.music.") + '">'
1058+
+ 'src="' + linkUrl.replace(/^https:\/\/.*?\//, "https://embed.music.apple.com/") + '">'
10581059
+ '</iframe>';
10591060
cardBody.appendChild(webPlayerDiv);
1061+
//YouTube - TODO: improve server-side to give brand and correct URL and return data.embedded
1062+
}else if (linkUrl.indexOf('youtube')){
1063+
var webPlayerDiv = document.createElement('DIV');
1064+
var playerId = currentLinkItemId++;
1065+
webPlayerDiv.className = "youTubeWebPlayer cardBodyItem fullWidthItem"
1066+
var f = document.createElement('iframe');
1067+
f.id = 'youTubeWebPlayer-' + playerId;
1068+
f.allow = "autoplay; encrypted-media;";
1069+
f.frameBorder = 0;
1070+
f.style.width = "100%"; f.style.height = "280px"; f.style.overflow = "hidden";
1071+
f.style.border = "4px solid"; f.style.borderColor = "#212121";
1072+
f.onload = function(){
1073+
//API
1074+
if (!youTubeMessageListenerExists){
1075+
youTubeMessageListenerExists = true;
1076+
window.addEventListener('message', function(e){
1077+
if (e.origin == "https://www.youtube.com" && e.data && typeof e.data == "string" && e.data.indexOf("{") == 0){
1078+
var data = JSON.parse(e.data);
1079+
if (data && data.id){
1080+
//f.contentWindow.postMessage(JSON.stringify({event:'command', func:'stopVideo'}), "*"); //playVideo, paus.., stop.., next..,
1081+
if (data.event == 'onReady'){
1082+
$('#' + data.id)[0].contentWindow.postMessage(JSON.stringify({event:'command', func:'playVideo'}), "*");
1083+
}else if (data.event == 'infoDelivery' && data.info && data.info.playerState == -1){
1084+
//console.log(JSON.stringify(data));
1085+
//TODO: sometimes fails AND should not end up in an endless loop!
1086+
if (data.info.availableQualityLevels.length == 0){
1087+
$('#' + data.id)[0].contentWindow.postMessage(JSON.stringify({event:'command', func:'nextVideo'}), "*");
1088+
}
1089+
}
1090+
}
1091+
}
1092+
});
1093+
}
1094+
f.contentWindow.postMessage(JSON.stringify({event:'listening', id: f.id}), "*");
1095+
};
1096+
//https://www.youtube.com/results?search_query=purple+haze%2C+jimi+hendrix
1097+
f.src = "https://www.youtube.com/embed?autoplay=1&enablejsapi=1&listType=search&list=" + linkUrl.replace(/.*?search_query=/, "").trim();
1098+
cardBody.appendChild(webPlayerDiv);
1099+
webPlayerDiv.appendChild(f);
10601100
}
10611101
}
10621102

@@ -1348,7 +1388,7 @@ function sepiaFW_build_ui_cards(){
13481388
var $scrollContainer = $container.closest('.sepiaFW-results-container');
13491389
var y = $scrollContainer.scrollTop();
13501390
$scrollContainer.animate({ scrollTop: y + 60 }, animTime);
1351-
}, animTime);
1391+
}, animTime + 50);
13521392
}
13531393
}
13541394
}

0 commit comments

Comments
 (0)