@@ -260,73 +260,85 @@ SDL.AudioModel = Em.Object.extend({
260260 /**
261261 * Turn on CD
262262 */
263- turnOnCD : function ( ) {
263+ turnOnCD : function ( event = null , is_background = false ) {
264264 if ( ! SDL . States . media . player . cd . active ) {
265265 this . deactivateAll ( ) ;
266- SDL . States . goToStates ( 'media.player.cd' ) ;
266+ this . changeAudioSource ( 'media.player.cd' , is_background ) ;
267+ }
268+ if ( ! is_background ) {
269+ this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . cdModel , 'cd' ) ;
267270 }
268- this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . cdModel , 'cd' ) ;
269271 this . returnParameters ( ) ;
270272 } ,
271273
272274 /**
273275 * Turn on USB
274276 */
275- turnOnUSB : function ( ) {
277+ turnOnUSB : function ( event = null , is_background = false ) {
276278 if ( ! SDL . States . media . player . usb . active ) {
277279 this . deactivateAll ( ) ;
278- SDL . States . goToStates ( 'media.player.usb' ) ;
280+ this . changeAudioSource ( 'media.player.usb' , is_background ) ;
281+ }
282+ if ( ! is_background ) {
283+ this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . usbModel , 'usb' ) ;
279284 }
280- this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . usbModel , 'usb' ) ;
281285 this . returnParameters ( ) ;
282286 } ,
283287
284288 /**
285289 * Turn on Radio
286290 */
287- turnOnRadio : function ( ) {
291+ turnOnRadio : function ( event = null , is_background = false ) {
288292 if ( ! SDL . States . media . player . radio . active ) {
289293 this . deactivateAll ( ) ;
290- SDL . States . goToStates ( 'media.player.radio' ) ;
294+ this . changeAudioSource ( 'media.player.radio' , is_background ) ;
291295 }
292296 SDL . RCModulesController . currentRadioModel . saveCurrentOptions ( ) ;
293- SDL . RCModulesController . currentRadioModel . set ( 'active' , true ) ;
297+ if ( ! is_background ) {
298+ SDL . RCModulesController . currentRadioModel . set ( 'active' , true ) ;
299+ }
294300 this . returnParameters ( ) ;
295301 } ,
296302
297303 /**
298304 * Turn on Bluetooth
299305 */
300- turnOnBluetooth : function ( ) {
306+ turnOnBluetooth : function ( event = null , is_background = false ) {
301307 if ( ! SDL . States . media . player . bluetooth . active ) {
302308 this . deactivateAll ( ) ;
303- SDL . States . goToStates ( 'media.player.bluetooth' ) ;
309+ this . changeAudioSource ( 'media.player.bluetooth' , is_background ) ;
310+ }
311+ if ( ! is_background ) {
312+ this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . bluetoothModel , 'bluetooth' ) ;
304313 }
305- this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . bluetoothModel , 'bluetooth' ) ;
306314 this . returnParameters ( ) ;
307315 } ,
308316
309317 /**
310318 * Turn on LineIn
311319 */
312- turnOnLineIn : function ( ) {
320+ turnOnLineIn : function ( event = null , is_background = false ) {
313321 if ( ! SDL . States . media . player . lineIn . active ) {
314322 this . deactivateAll ( ) ;
315- SDL . States . goToStates ( 'media.player.lineIn' ) ;
323+ this . changeAudioSource ( 'media.player.lineIn' , is_background ) ;
324+ }
325+ if ( ! is_background ) {
326+ this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . lineInModel , 'lineIn' ) ;
316327 }
317- this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . lineInModel , 'lineIn' ) ;
318328 this . returnParameters ( ) ;
319329 } ,
320330
321331 /**
322332 * Turn on IPod
323333 */
324- turnOnIPod : function ( ) {
334+ turnOnIPod : function ( event = null , is_background = false ) {
325335 if ( ! SDL . States . media . player . ipod . active ) {
326336 this . deactivateAll ( ) ;
327- SDL . States . goToStates ( 'media.player.ipod' ) ;
337+ this . changeAudioSource ( 'media.player.ipod' , is_background ) ;
338+ }
339+ if ( ! is_background ) {
340+ this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . ipodModel , 'ipod' ) ;
328341 }
329- this . onPlayerEnter ( SDL . RCModulesController . currentAudioModel . ipodModel , 'ipod' ) ;
330342 this . returnParameters ( ) ;
331343 } ,
332344
@@ -544,12 +556,12 @@ SDL.AudioModel = Em.Object.extend({
544556 this . changeSourceFromBluetooth ( is_background ) ;
545557 break ;
546558 }
547- case 'media.player.lieIn ' : {
559+ case 'media.player.lineIn ' : {
548560 this . changeSourceFromLineIn ( is_background ) ;
549561 break ;
550562 }
551563 case 'media.player.ipod' : {
552- this . changeSourceFromIpod ( is_background ) ;
564+ this . changeSourceFromIPod ( is_background ) ;
553565 break ;
554566 }
555567 default : {
@@ -558,17 +570,63 @@ SDL.AudioModel = Em.Object.extend({
558570 }
559571 } ,
560572
573+ /**
574+ * Switch RC Audio source based on whether the app is in focus
575+ * @param nextState Audio source to transition to
576+ * @param isBackground
577+ */
578+ changeAudioSource : function ( nextState , isBackground ) {
579+ if ( ! isBackground ) {
580+ SDL . States . goToStates ( nextState ) ;
581+ return ;
582+ }
583+
584+ SDL . RCModulesController . currentAudioModel . set ( 'activeState' , nextState ) ;
585+ if ( FFW . RC . isSetVdInProgress ) {
586+ return ;
587+ }
588+ let currentAudioModel = this . getAudioModel ( nextState ) ;
589+ currentAudioModel . sendAudioNotification ( ) ;
590+ } ,
591+
592+ /**
593+ * Get audio model based on state name
594+ * @param stateName name of audio source state(e.g. 'media.player.ipod')
595+ */
596+ getAudioModel : function ( stateName ) {
597+ switch ( stateName ) {
598+ case 'media.player.radio' : {
599+ return SDL . RCModulesController . currentRadioModel ;
600+ }
601+ case 'media.player.cd' : {
602+ return SDL . RCModulesController . currentAudioModel . cdModel ;
603+ }
604+ case 'media.player.usb' : {
605+ return SDL . RCModulesController . currentAudioModel . usbModel ;
606+ }
607+ case 'media.player.bluetooth' : {
608+ return SDL . RCModulesController . currentAudioModel . bluetoothModel ;
609+ }
610+ case 'media.player.lineIn' : {
611+ return SDL . RCModulesController . currentAudioModel . lineInModel ;
612+ }
613+ case 'media.player.ipod' : {
614+ return SDL . RCModulesController . currentAudioModel . ipodModel ;
615+ }
616+ default : { // Default to RADIO
617+ return SDL . RCModulesController . currentRadioModel ;
618+ }
619+ }
620+ } ,
621+
561622 /**
562623 * Switches to next after radio source
563624 * @param is source switched from background or not
564625 */
565626 changeSourceFromRadio : function ( is_background ) {
566627 var old_state = SDL . States . currentState . get ( 'path' ) ;
567628 this . deactivateRadio ( ) ;
568- this . turnOnCD ( ) ;
569- if ( is_background ) {
570- SDL . States . goToStates ( old_state ) ;
571- }
629+ this . turnOnCD ( null , is_background ) ;
572630 } ,
573631
574632 /**
@@ -578,10 +636,7 @@ SDL.AudioModel = Em.Object.extend({
578636 changeSourceFromCD : function ( is_background ) {
579637 var old_state = SDL . States . currentState . get ( 'path' ) ;
580638 this . deactivateCD ( ) ;
581- this . turnOnUSB ( ) ;
582- if ( is_background ) {
583- SDL . States . goToStates ( old_state ) ;
584- }
639+ this . turnOnUSB ( null , is_background ) ;
585640 } ,
586641
587642 /**
@@ -591,14 +646,7 @@ SDL.AudioModel = Em.Object.extend({
591646 changeSourceFromUSB : function ( is_background ) {
592647 var old_state = SDL . States . currentState . get ( 'path' ) ;
593648 this . deactivateUSB ( ) ;
594- if ( SDL . SDLMediaController . currentAppId != null && ! is_background ) {
595- SDL . SDLMediaController . activateCurrentApp ( ) ;
596- } else {
597- this . turnOnRadio ( ) ;
598- }
599- if ( is_background ) {
600- SDL . States . goToStates ( old_state ) ;
601- }
649+ this . turnOnBluetooth ( null , is_background ) ;
602650 } ,
603651
604652 /**
@@ -608,10 +656,7 @@ SDL.AudioModel = Em.Object.extend({
608656 changeSourceFromBluetooth : function ( is_background ) {
609657 var old_state = SDL . States . currentState . get ( 'path' ) ;
610658 this . deactivateBluetooth ( ) ;
611- this . turnOnLineIn ( ) ;
612- if ( is_background ) {
613- SDL . States . goToStates ( old_state ) ;
614- }
659+ this . turnOnLineIn ( null , is_background ) ;
615660 } ,
616661
617662 /**
@@ -621,22 +666,20 @@ SDL.AudioModel = Em.Object.extend({
621666 changeSourceFromLineIn : function ( is_background ) {
622667 var old_state = SDL . States . currentState . get ( 'path' ) ;
623668 this . deactivateLineIn ( ) ;
624- this . turnOnIpod ( ) ;
625- if ( is_background ) {
626- SDL . States . goToStates ( old_state ) ;
627- }
669+ this . turnOnIPod ( null , is_background ) ;
628670 } ,
629671
630672 /**
631673 * Switches to next after IPod source
632674 * @param is source switched from background or not
633675 */
634- changeSourceFromIpod : function ( is_background ) {
676+ changeSourceFromIPod : function ( is_background ) {
635677 var old_state = SDL . States . currentState . get ( 'path' ) ;
636- this . deactivateIpod ( ) ;
637- this . turnOnIpod ( ) ;
638- if ( is_background ) {
639- SDL . States . goToStates ( old_state ) ;
678+ this . deactivateIPod ( ) ;
679+ if ( SDL . SDLMediaController . currentAppId != null && ! is_background ) {
680+ SDL . SDLMediaController . activateCurrentApp ( ) ;
681+ } else {
682+ this . turnOnRadio ( null , is_background ) ;
640683 }
641684 } ,
642685
@@ -646,10 +689,7 @@ SDL.AudioModel = Em.Object.extend({
646689 */
647690 changeSourceFromUnknown : function ( is_background ) {
648691 var old_state = SDL . States . currentState . get ( 'path' ) ;
649- this . turnOnRadio ( ) ;
650- if ( is_background ) {
651- SDL . States . goToStates ( old_state ) ;
652- }
692+ this . turnOnRadio ( null , is_background ) ;
653693 } ,
654694
655695 /**
0 commit comments