Skip to content

Commit b6e7749

Browse files
committed
improved audio setTitle + volume controls + fixes for mediaPlayer;
1 parent 3b33cc0 commit b6e7749

12 files changed

+319
-64
lines changed

www/scripts/sepiaFW.android.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ function sepiaFW_build_android(){
129129
}
130130
if (intent.extras.playing){
131131
if (intent.extras.artist && intent.extras.track){
132-
SepiaFW.audio.setPlayerTitle(intent.extras.artist + " - " + intent.extras.track, '');
132+
SepiaFW.audio.setPlayerTitle(intent.extras.artist + " - " + intent.extras.track, 'android-intent');
133133
}else if (intent.extras.track){
134-
SepiaFW.audio.setPlayerTitle(intent.extras.track, '');
134+
SepiaFW.audio.setPlayerTitle(intent.extras.track, 'android-intent');
135135
}
136136
}else{
137137
SepiaFW.audio.setPlayerTitle('', '');

www/scripts/sepiaFW.app.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ function sepiaFW_build_config(){
311311
"spotify_embedded": {name: "Spotify Widget"},
312312
"apple_music_link": {name: "Apple Music Web"},
313313
"apple_music_embedded": {name: "Apple Music Widget"}
314+
//"soundcloud_embedded": {name: "SoundCloud Widget"}
314315
}
315-
var defaultMusicApp = "embedded";
316+
var defaultMusicApp = "youtube_embedded";
316317

317318
Config.getMusicAppCollection = function(){
318319
if (SepiaFW.ui.isAndroid){

www/scripts/sepiaFW.audio.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ function sepiaFW_build_audio(){
248248
&& ((new Date().getTime() - SepiaFW.android.lastReceivedMediaAppTS) < (1000*60*15)); //This is pure guessing ...
249249
return isInternalPlayerStreaming || isEmbeddedMediaPlayerStreaming || isAndroidPlayerStreaming;
250250
}
251-
AudioPlayer.getLastActiveAudioStreamPlayer = function(){
251+
AudioPlayer.getLastActiveAudioSource = function(){
252252
return lastAudioPlayerEventSource;
253253
}
254254

255255
//controls
256256
var audioTitle;
257+
var currentAudioTitleBelongsToStreamPlayer = true; //default: true
257258
var audioStartBtn;
258259
var audioStopBtn;
259260
var audioVolUp;
@@ -395,24 +396,38 @@ function sepiaFW_build_audio(){
395396
audioTitle = document.getElementById('sepiaFW-audio-ctrls-title');
396397
audioStartBtn = document.getElementById('sepiaFW-audio-ctrls-start');
397398
$(audioStartBtn).off().on('click', function(){
398-
//NOTE: for now this is "internal" player only (as volume control)
399-
if (!AudioPlayer.initAudio(function(){ AudioPlayer.playURL('', player); })){
400-
AudioPlayer.playURL('', player);
401-
}
399+
AudioPlayer.initAudio(undefined, function(){
400+
if (currentAudioTitleBelongsToStreamPlayer){
401+
//we keep this for now...
402+
AudioPlayer.playURL('', "stream");
403+
}else{
404+
SepiaFW.client.controls.media({
405+
action: "resume",
406+
skipFollowUp: true
407+
});
408+
}
409+
});
402410
});
403411
audioStopBtn = document.getElementById('sepiaFW-audio-ctrls-stop');
404412
$(audioStopBtn).off().on('click', function(){
405413
SepiaFW.client.controls.media({
406-
action: "stop"
414+
action: "stop",
415+
skipFollowUp: true
407416
});
408417
});
409418
audioVolUp = document.getElementById('sepiaFW-audio-ctrls-volup');
410419
$(audioVolUp).off().on('click', function(){
411-
playerSetVolume(playerGetVolume() + 1.0);
420+
//playerSetVolume(playerGetVolume() + 1.0);
421+
SepiaFW.client.controls.volume({
422+
action: "up"
423+
});
412424
});
413425
audioVolDown = document.getElementById('sepiaFW-audio-ctrls-voldown');
414426
$(audioVolDown).off().on('click', function(){
415-
playerSetVolume(playerGetVolume() - 1.0);
427+
//playerSetVolume(playerGetVolume() - 1.0);
428+
SepiaFW.client.controls.volume({
429+
action: "down"
430+
});
416431
});
417432
audioVol = document.getElementById('sepiaFW-audio-ctrls-vol');
418433
if (audioVol) audioVol.textContent = Math.round(player.volume*10.0);
@@ -425,7 +440,8 @@ function sepiaFW_build_audio(){
425440
//TODO: is this still up-to-date?
426441
return (!SepiaFW.ui.isStandaloneWebApp && (SepiaFW.ui.isMobile || SepiaFW.ui.isSafari) && doInitAudio);
427442
}
428-
AudioPlayer.initAudio = function(continueCallback){
443+
AudioPlayer.initAudio = function(continueCallback, noopOrContinueCallback){
444+
if (noopOrContinueCallback && !continueCallback) continueCallback = noopOrContinueCallback;
429445
//workaround for mobile devices to activate audio by scripts
430446
if (AudioPlayer.requiresInit()){
431447
SepiaFW.debug.info('Audio - trying to initialize players');
@@ -451,6 +467,7 @@ function sepiaFW_build_audio(){
451467
return true;
452468

453469
}else{
470+
if (noopOrContinueCallback) noopOrContinueCallback();
454471
return false;
455472
}
456473
}
@@ -726,7 +743,7 @@ function sepiaFW_build_audio(){
726743
var setVol = getValidVolume(newVol)/10.0;
727744
player.volume = setVol;
728745
orgVolume = setVol;
729-
$('#sepiaFW-audio-ctrls-vol').html(Math.floor(setVol*10.0));
746+
$('#sepiaFW-audio-ctrls-vol').text(Math.floor(setVol*10.0));
730747
SepiaFW.debug.info('AUDIO: volume set (and stored) to ' + setVol);
731748
broadcastPlayerVolumeSet();
732749
}
@@ -750,7 +767,7 @@ function sepiaFW_build_audio(){
750767
if (mainAudioIsOnHold || (SepiaFW.speech.isSpeakingOrListening())){
751768
var setVol = getValidVolume(newVol)/10.0;
752769
orgVolume = setVol;
753-
$('#sepiaFW-audio-ctrls-vol').html(Math.floor(setVol*10.0));
770+
$('#sepiaFW-audio-ctrls-vol').text(Math.floor(setVol*10.0));
754771
SepiaFW.debug.info('AUDIO: unfaded volume set to ' + setVol);
755772
broadcastPlayerVolumeSet();
756773
}else{
@@ -765,7 +782,7 @@ function sepiaFW_build_audio(){
765782
var lastStream = SepiaFW.audio.getLastAudioStream();
766783
var lastStreamTitle = (lastStream)? SepiaFW.audio.getLastAudioStreamTitle() : "";
767784
SepiaFW.audio.playURL(lastStream, ''); //<-- potentially looses callBack info here, but since this is stopped
768-
SepiaFW.audio.setPlayerTitle(lastStreamTitle, '');
785+
SepiaFW.audio.setPlayerTitle(lastStreamTitle, "stream");
769786
}
770787
SepiaFW.debug.info('AUDIO: fadeToOriginal - restore vol=' + orgVolume);
771788
$(player).stop(); //note: this is an animation stop
@@ -785,14 +802,19 @@ function sepiaFW_build_audio(){
785802
a.protocol == loc.protocol;
786803
}
787804

788-
//set title of player
789-
AudioPlayer.setPlayerTitle = function(newTitle, audioPlayer){
790-
if (!audioPlayer) audioPlayer = player;
791-
audioPlayer.title = newTitle;
792-
if (audioTitle) audioTitle.textContent = newTitle || "SEPIA Audio Player";
793-
if (audioPlayer == player){
805+
//set title of player - NOTE: compared to most functions below this is not limited to "stream" player
806+
AudioPlayer.setPlayerTitle = function(newTitle, playerTag){
807+
//playerTag: stream, embedded-media-player, android-intent
808+
if (playerTag == undefined) playerTag = "stream";
809+
if (playerTag == "stream" || playerTag == player){
810+
//Stream player
794811
lastAudioStreamTitle = newTitle;
812+
player.title = newTitle;
813+
currentAudioTitleBelongsToStreamPlayer = true;
814+
}else{
815+
currentAudioTitleBelongsToStreamPlayer = false;
795816
}
817+
if (audioTitle) audioTitle.textContent = newTitle || "SEPIA Audio Player";
796818
}
797819

798820
//get the stream last played
@@ -809,7 +831,7 @@ function sepiaFW_build_audio(){
809831
var lastStreamTitle = (lastStream)? AudioPlayer.getLastAudioStreamTitle() : "";
810832
if (lastStream){
811833
AudioPlayer.playURL(lastStream, player);
812-
AudioPlayer.setPlayerTitle(lastStreamTitle);
834+
AudioPlayer.setPlayerTitle(lastStreamTitle, "stream");
813835
return true;
814836
}else{
815837
return false;

www/scripts/sepiaFW.client.controls.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,58 @@ function sepiaFW_build_client_controls(sepiaSessionId){
161161
return false;
162162
}
163163
function volumeUp(){
164-
//$("#sepiaFW-audio-ctrls-volup").trigger('click', {bm_force : true});
165-
SepiaFW.audio.playerSetCurrentOrTargetVolume(SepiaFW.audio.getOriginalVolume() + 1.0);
164+
volumeAction(function(){
165+
SepiaFW.audio.playerSetCurrentOrTargetVolume(SepiaFW.audio.getOriginalVolume() + 1.0);
166+
}, function(emp){
167+
emp.volumeUp();
168+
$('#sepiaFW-audio-ctrls-vol').text("?");
169+
}, function(){
170+
//TODO: not supported yet
171+
$('#sepiaFW-audio-ctrls-vol').text("?");
172+
});
166173
}
167174
function volumeDown(){
168-
//$("#sepiaFW-audio-ctrls-voldown").trigger('click', {bm_force : true});
169-
SepiaFW.audio.playerSetCurrentOrTargetVolume(SepiaFW.audio.getOriginalVolume() - 1.0);
175+
volumeAction(function(){
176+
SepiaFW.audio.playerSetCurrentOrTargetVolume(SepiaFW.audio.getOriginalVolume() - 1.0);
177+
}, function(emp){
178+
emp.volumeDown();
179+
$('#sepiaFW-audio-ctrls-vol').text("?");
180+
}, function(){
181+
//TODO: not supported yet
182+
$('#sepiaFW-audio-ctrls-vol').text("?");
183+
});
170184
}
171185
function volumeSet(newVol){
172-
SepiaFW.audio.playerSetCurrentOrTargetVolume(newVol); //value between 0.0-10.0
186+
//value between 0.0-10.0
187+
volumeAction(function(){
188+
SepiaFW.audio.playerSetCurrentOrTargetVolume(newVol);
189+
}, function(emp){
190+
emp.volumeSet(newVol);
191+
$('#sepiaFW-audio-ctrls-vol').text("?");
192+
}, function(){
193+
//TODO: not supported yet
194+
$('#sepiaFW-audio-ctrls-vol').text("?");
195+
});
196+
}
197+
function volumeAction(streamPlayerFun, embeddedPlayerFun, androidFun){
198+
var lastActivePlayer = SepiaFW.audio.getLastActiveAudioSource();
199+
var emp = SepiaFW.ui.cards.embed.getActiveMediaPlayer();
200+
//find right player
201+
if (!lastActivePlayer || lastActivePlayer == "stream"){
202+
//default
203+
streamPlayerFun();
204+
return true;
205+
}else if (lastActivePlayer == "embedded-media-player"){
206+
//Embedded media player
207+
if (emp && emp.isReady()){
208+
embeddedPlayerFun(emp);
209+
return true;
210+
}
211+
}else if (lastActivePlayer == "android-intent" && SepiaFW.ui.isAndroid){
212+
//Android intent controls
213+
androidFun();
214+
return true;
215+
}
173216
}
174217

175218
//Media player controls
@@ -220,7 +263,7 @@ function sepiaFW_build_client_controls(sepiaSessionId){
220263
//RESUME
221264
}else if (controlData.action == "resume"){
222265
//try to find last active player
223-
var lastActivePlayer = SepiaFW.audio.getLastActiveAudioStreamPlayer();
266+
var lastActivePlayer = SepiaFW.audio.getLastActiveAudioSource();
224267
var isAnyPlayerStreaming = SepiaFW.audio.isAnyAudioSourceActive();
225268
var sentEvent = false;
226269

@@ -240,6 +283,10 @@ function sepiaFW_build_client_controls(sepiaSessionId){
240283
SepiaFW.debug.info("Client controls - Media: resuming embedded media player");
241284
sentEvent = true;
242285
emp.play();
286+
}else{
287+
//add note that media-player was killed?
288+
SepiaFW.ui.showInfo("Active Media-Player widget was removed");
289+
//TODO: send custom follow up?
243290
}
244291

245292
}else if (lastActivePlayer == "android-intent" && SepiaFW.ui.isAndroid){
@@ -265,7 +312,7 @@ function sepiaFW_build_client_controls(sepiaSessionId){
265312
//NEXT
266313
}else if (controlData.action == "next"){
267314
//try to find last active player
268-
var lastActivePlayer = SepiaFW.audio.getLastActiveAudioStreamPlayer();
315+
var lastActivePlayer = SepiaFW.audio.getLastActiveAudioSource();
269316
var sentEvent = false;
270317

271318
//find right player

www/scripts/sepiaFW.embedded.services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function sepiaFW_build_embedded_services(){
254254
var serviceResult;
255255
if (SepiaFW.offline){
256256
var cardInfo = [SepiaFW.offline.getLinkCard(url, title, description, imageUrl, imageBackground, data)];
257-
var actionInfo = [SepiaFW.offline.getUrlOpenAction(url)];
257+
var actionInfo = [SepiaFW.offline.getUrlOpenAction(url, true)]; //skipIfEmbeddable = true
258258
var htmlInfo = "";
259259
serviceResult = Services.buildServiceResult(
260260
nluInput.user, nluInput.language,

www/scripts/sepiaFW.offline.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ function sepiaFW_build_offline(){
77
//more at: SepiaFW.embedded.services
88

99
//Get action to open an URL
10-
Offline.getUrlOpenAction = function(_url){
10+
Offline.getUrlOpenAction = function(_url, skipIfEmbeddable){
1111
var action = {
1212
type: "open_in_app_browser",
13-
url: _url
13+
url: _url,
14+
skipIfEmbeddable: (skipIfEmbeddable || false)
1415
}
1516
return action;
1617
}
@@ -87,6 +88,9 @@ function sepiaFW_build_offline(){
8788
"type": "musicSearch",
8889
"brand": "Spotify"
8990
*/
91+
data.type = imageUrl? "custom" : "default";
92+
data.typeData = undefined;
93+
//var embedData = SepiaFW.ui.cards.canEmbedUrl(url); //handled by Cards by default
9094
var cardInfoItem = {
9195
"cardType": "single",
9296
"N": 1,

www/scripts/sepiaFW.teach.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ function sepiaFW_build_teach(sepiaSessionId){
396396
});
397397
}
398398

399+
//TODO: replace ancient pop-up functions with 'UI.showPopup' (or convenience version)
400+
399401
//parameter input help box pop-up
400402
function showInputHelpPopup(paramName, value, assignFun, type, examples){
401403
var $box = $('#sepiaFW-teachUI-input-helper');

www/scripts/sepiaFW.ui.actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ function sepiaFW_build_ui_actions(){
404404
SepiaFW.audio.playURL(action.audio_url, '', function(){
405405
SepiaFW.audio.playerFadeToOriginalVolume();
406406
});//, onEndCallback, onErrorCallback)
407-
SepiaFW.audio.setPlayerTitle(action.audio_title, '');
407+
SepiaFW.audio.setPlayerTitle(action.audio_title, 'stream');
408408
}
409409
//STOP AUDIO STREAM
410410
Actions.stopAudio = function(action){

0 commit comments

Comments
 (0)