Skip to content

Commit 0671018

Browse files
committed
implementing new media-player widgets (wip, alpha)
1 parent 243253a commit 0671018

File tree

7 files changed

+94
-28
lines changed

7 files changed

+94
-28
lines changed

www/css/sepiaFW-cards.css

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,28 @@
402402

403403
/* --- Embedded Media Player --- */
404404

405-
/* .sepiaFW-cards-flexSize-container.sepia-embedded-player-card {} */
406-
405+
.sepiaFW-cards-flexSize-container.sepia-embedded-player-card {
406+
margin-bottom: 10px;
407+
}
407408
.sepiaFW-cards-flexSize-container .sepiaFW-embedded-player-container iframe {
408-
border: 1px solid #000;
409+
border: 0;
410+
border-radius: 3px;
411+
transition: height .3s;
412+
}
413+
.sepiaFW-cards-flexSize-container .sepiaFW-embedded-player-container .cardItemOverlay {
414+
position: absolute;
415+
top: 0;
416+
left: 0;
417+
width: 100%;
418+
height: 100%;
419+
background: #eee;
420+
color: #000;
421+
display: flex;
422+
justify-content: center;
423+
align-items: center;
424+
}
425+
.sepiaFW-cards-flexSize-container .sepiaFW-embedded-player-container .cardItemOverlay p {
426+
animation: sepiaFW-animation-blink 3s infinite;
409427
}
410428

411429
/* --- Time events --- */

www/scripts/sepiaFW.android.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ function sepiaFW_build_android(){
1313
Android.musicApps = {
1414
"system": {name: "System", package: ""},
1515
"select": {name: "Select", package: ""},
16-
"youtube": {name: "YouTube", package: "com.google.android.youtube"},
16+
"embedded": {name: "Embedded Player", package: ""},
17+
"youtube": {name: "YouTube App", package: "com.google.android.youtube"},
18+
"youtube_link": {name: "YouTube Web", package: "com.google.android.youtube"},
19+
"youtube_embedded": {name: "YouTube Widget", package: "com.google.android.youtube"},
1720
"spotify": {name: "Spotify App", package: "com.spotify.music"},
18-
"spotify_link": {name: "Spotify URI", package: "com.spotify.music"},
21+
"spotify_link": {name: "Spotify Web", package: "com.spotify.music"},
22+
"spotify_embedded": {name: "Spotify Widget", package: "com.spotify.music"},
1923
"apple_music": {name: "Apple Music App", package: "com.apple.android.music"},
20-
"apple_music_link": {name: "Apple Music URI", package: "com.apple.android.music"},
24+
"apple_music_link": {name: "Apple Music Web", package: "com.apple.android.music"},
25+
"apple_music_embedded": {name: "Apple Music Widget", package: "com.apple.android.music"},
2126
//"amazon_music": {name: "Amazon Music", package: "com.amazon.mp3"},
2227
//"soundcloud": {name: "SoundCloud", package: "com.soundcloud.android"},
2328
//"deezer": {name: "Deezer", package: "deezer.android.app"},

www/scripts/sepiaFW.app.config.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,16 @@ function sepiaFW_build_config(){
303303

304304
//Collection of universally supported apps and their names
305305
Config.musicApps = {
306-
"youtube": {name: "YouTube"},
307-
"spotify_link": {name: "Spotify"},
308-
"apple_music_link": {name: "Apple Music"}
306+
//NOTE: _link services will skip 'Controls.searchForMusic' action (server will not send it)
307+
"embedded": {name: "Embedded Player"},
308+
"youtube_link": {name: "YouTube Web"},
309+
"youtube_embedded": {name: "YouTube Widget"},
310+
"spotify_link": {name: "Spotify Web"},
311+
"spotify_embedded": {name: "Spotify Widget"},
312+
"apple_music_link": {name: "Apple Music Web"},
313+
"apple_music_embedded": {name: "Apple Music Widget"}
309314
}
310-
var defaultMusicApp = "youtube";
315+
var defaultMusicApp = "embedded";
311316

312317
Config.getMusicAppCollection = function(){
313318
if (SepiaFW.ui.isAndroid){

www/scripts/sepiaFW.audio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ function sepiaFW_build_audio(){
886886

887887
//console.log("Audio-URL: " + audioURL); //DEBUG
888888
audioPlayer.src = audioURL;
889-
audioPlayer.oncanplay = function() {
889+
audioPlayer.oncanplay = function(){
890890
SepiaFW.debug.info("AUDIO: can be played now (oncanplay event)"); //debug
891891
if (audioPlayer == player){
892892
Stream.isPlaying = true;

www/scripts/sepiaFW.client.controls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function sepiaFW_build_client_controls(sepiaSessionId){
299299
console.log('URI: ' + controlData.uri);
300300
*/
301301

302-
//Stop other players
302+
//Stop other players - TODO: move down?
303303
Controls.media({
304304
action: "stop",
305305
skipFollowUp: true

www/scripts/sepiaFW.ui.cards.embed.js

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function sepiaFW_build_ui_cards_embed(){
1010
- Make sure only one is active
1111
- Implement async. callback with msgId and timeout
1212
*/
13+
var playerWidgets = {
14+
spotify: "<assist_server>/widgets/mp-spotify.html",
15+
apple_music: "<assist_server>/widgets/mp-apple-music.html",
16+
youtube: "<assist_server>/widgets/mp-youtube.html"
17+
}
1318

1419
var activeMediaPlayers = {};
1520

@@ -46,7 +51,7 @@ function sepiaFW_build_ui_cards_embed(){
4651
//Create media player DOM element
4752
function createMediaPlayerDomElement(id, contentUrl, onLoadHandler){
4853
//card
49-
var mediaPlayerDiv = document.createElement('DIV');
54+
var mediaPlayerDiv = document.createElement('div');
5055
mediaPlayerDiv.id = id;
5156
mediaPlayerDiv.className = "embeddedWebPlayer cardBodyItem fullWidthItem";
5257
//iframe
@@ -59,8 +64,13 @@ function sepiaFW_build_ui_cards_embed(){
5964
//iframe.allow = ...;
6065
//iframe.sandbox = ...;
6166
mediaPlayerDiv.appendChild(iframe);
67+
//loading overlay
68+
var loadOverlay = document.createElement('div');
69+
loadOverlay.className = "cardItemOverlay";
70+
loadOverlay.innerHTML = "<p>Loading</p>";
71+
mediaPlayerDiv.appendChild(loadOverlay);
6272
return {
63-
card: mediaPlayerDiv, iframe: iframe
73+
card: mediaPlayerDiv, iframe: iframe, overlay: loadOverlay
6474
}
6575
}
6676

@@ -100,22 +110,42 @@ function sepiaFW_build_ui_cards_embed(){
100110
}, "*");
101111
}
102112
thisPlayer.eventHandler = function(ev){
103-
//TODO: use
104113
console.error("ev", playerId, ev); //DEBUG
114+
if (ev.state){
115+
stateHandler(ev);
116+
}
105117
}
106118

107119
//States
120+
var state = 0; //0: created, 1: ready, 2: playing, 3: paused, 10: error
121+
122+
function stateHandler(ev){
123+
if (ev.state == 1){
124+
//on-ready
125+
state = ev.state;
126+
if (ev.size && ev.size.height){
127+
thisPlayer.iframe.style.height = ev.size.height;
128+
}
129+
setTimeout(function(){ $(mpObj.overlay).remove(); }, 500);
130+
}else if (ev.state == 2){
131+
//on-play
132+
state = ev.state;
133+
}else if (ev.state == 3){
134+
//on-pause
135+
state = ev.state;
136+
}else if (ev.state == 10){
137+
//on-error
138+
state = ev.state;
139+
}
140+
}
108141

109142
//Controls - TODO: implement
110-
thisPlayer.start = function(doneCallback, errorCallback){
111-
sendEvent({controls: "start"});
143+
thisPlayer.play = function(doneCallback, errorCallback){
144+
sendEvent({controls: "play"});
112145
}
113146
thisPlayer.pause = function(doneCallback, errorCallback){
114147
sendEvent({controls: "pause"});
115148
}
116-
thisPlayer.resume = function(doneCallback, errorCallback){
117-
sendEvent({controls: "resume"});
118-
}
119149
thisPlayer.fadeOut = function(doneCallback, errorCallback){
120150
sendEvent({controls: "fadeOut"});
121151
}
@@ -128,6 +158,13 @@ function sepiaFW_build_ui_cards_embed(){
128158
thisPlayer.previous = function(doneCallback, errorCallback){
129159
sendEvent({controls: "previous"});
130160
}
161+
thisPlayer.volumeUp = function(doneCallback, errorCallback){
162+
sendEvent({controls: "volumeUp"});
163+
}
164+
thisPlayer.volumeDown = function(doneCallback, errorCallback){
165+
sendEvent({controls: "volumeDown"});
166+
}
167+
131168
//stop, release resources and remove handle
132169
thisPlayer.release = function(doneCallback, errorCallback){
133170

www/scripts/sepiaFW.ui.cards.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ function sepiaFW_build_ui_cards(){
2525
var topIndexZ = 1; //to get an active element to the top (deprecated?)
2626

2727
//some specials
28+
Cards.canEmbedCustomPlayer = true;
2829
Cards.canEmbedYouTube = true;
2930
Cards.canEmbedSpotify = false; //deactivated by default because it only works in desktop and gives no control over start/stop/volume
30-
Cards.canEmbedAppleMusic = false; //"" ""
31+
Cards.canEmbedAppleMusic = false; // "" ""
3132
Cards.canEmbedWebPlayer = function(service){
3233
if (!service) return false;
33-
service = service.toLowerCase().replace(/\s+/,"_"); //support brands too
34-
if (service.indexOf("custom_embedded") == 0){
35-
return true;
34+
service = service.toLowerCase().replace(/\s+/, "_"); //support brands too
35+
if (service.indexOf("embedded") == 0){
36+
return Cards.canEmbedCustomPlayer;
3637
}else if (service.indexOf("spotify") == 0){
3738
return Cards.canEmbedSpotify;
3839
}else if (service.indexOf("apple_music") == 0){
@@ -45,7 +46,7 @@ function sepiaFW_build_ui_cards(){
4546
}
4647
Cards.getSupportedWebPlayers = function(){
4748
var players = [];
48-
players.push("custom_embedded");
49+
if (Cards.canEmbedCustomPlayer) players.push("embedded");
4950
if (Cards.canEmbedYouTube) players.push("youtube");
5051
if (Cards.canEmbedSpotify) players.push("spotify");
5152
if (Cards.canEmbedAppleMusic) players.push("apple_music");
@@ -2131,14 +2132,14 @@ function sepiaFW_build_ui_cards(){
21312132
parentElement: cardBody,
21322133
widgetUrl: widgetUrl
21332134
});
2134-
var cardEle = document.createElement('DIV');
2135+
var cardEle = document.createElement('div');
21352136
cardEle.className = 'cardBodyItem radioStation'; //lazy styling: use radioStation
21362137
var buttons = [{
21372138
icon: "skip_previous",
21382139
fun: player.previous
21392140
},{
21402141
icon: "play_arrow",
2141-
fun: player.start
2142+
fun: player.play
21422143
},{
21432144
icon: "pause",
21442145
fun: player.pause
@@ -2147,7 +2148,7 @@ function sepiaFW_build_ui_cards(){
21472148
fun: player.next
21482149
}];
21492150
buttons.forEach(function(b){
2150-
var btn = document.createElement('DIV');
2151+
var btn = document.createElement('div');
21512152
btn.className = "itemLeft radioLeft";
21522153
btn.innerHTML = "<i class='material-icons md-mnu'>" + b.icon + "</i>";
21532154
$(btn).on("click", b.fun);

0 commit comments

Comments
 (0)