mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1290467 - part10 : update audio focus related control operations. r=sebastian
Except controlling audio focus from gecko, the MediaControlService can also decide whether needs to request or abandon audio focus. MozReview-Commit-ID: G3iSYwd24JZ --HG-- extra : rebase_source : dd29207d8c08176cd7a57f08d3361e4f29c4095a
This commit is contained in:
parent
ff8012b391
commit
e9a55e8604
@ -56,13 +56,13 @@ public class AudioFocusAgent {
|
||||
case AudioManager.AUDIOFOCUS_LOSS:
|
||||
Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_LOSS");
|
||||
notifyObservers("AudioFocusChanged", "lostAudioFocus");
|
||||
notifyMediaControlService(MediaControlService.ACTION_PAUSE);
|
||||
notifyMediaControlService(MediaControlService.ACTION_PAUSE_BY_AUDIO_FOCUS);
|
||||
mAudioFocusState = LOST_FOCUS;
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
||||
Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_LOSS_TRANSIENT");
|
||||
notifyObservers("AudioFocusChanged", "lostAudioFocusTransiently");
|
||||
notifyMediaControlService(MediaControlService.ACTION_PAUSE);
|
||||
notifyMediaControlService(MediaControlService.ACTION_PAUSE_BY_AUDIO_FOCUS);
|
||||
mAudioFocusState = LOST_FOCUS_TRANSIENT;
|
||||
break;
|
||||
case AudioManager.AUDIOFOCUS_GAIN:
|
||||
@ -71,7 +71,7 @@ public class AudioFocusAgent {
|
||||
}
|
||||
Log.d(LOGTAG, "onAudioFocusChange, AUDIOFOCUS_GAIN");
|
||||
notifyObservers("AudioFocusChanged", "gainAudioFocus");
|
||||
notifyMediaControlService(MediaControlService.ACTION_RESUME);
|
||||
notifyMediaControlService(MediaControlService.ACTION_RESUME_BY_AUDIO_FOCUS);
|
||||
mAudioFocusState = OWN_FOCUS;
|
||||
break;
|
||||
default:
|
||||
|
@ -37,6 +37,8 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
public static final String ACTION_RESUME = "action_resume";
|
||||
public static final String ACTION_PAUSE = "action_pause";
|
||||
public static final String ACTION_STOP = "action_stop";
|
||||
public static final String ACTION_RESUME_BY_AUDIO_FOCUS = "action_resume_audio_focus";
|
||||
public static final String ACTION_PAUSE_BY_AUDIO_FOCUS = "action_pause_audio_focus";
|
||||
|
||||
private static final int MEDIA_CONTROL_ID = 1;
|
||||
private static final String MEDIA_CONTROL_PREF = "dom.audiochannel.mediaControl";
|
||||
@ -171,6 +173,12 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
case ACTION_STOP :
|
||||
mController.getTransportControls().stop();
|
||||
break;
|
||||
case ACTION_PAUSE_BY_AUDIO_FOCUS :
|
||||
mController.getTransportControls().sendCustomAction(ACTION_PAUSE_BY_AUDIO_FOCUS, null);
|
||||
break;
|
||||
case ACTION_RESUME_BY_AUDIO_FOCUS :
|
||||
mController.getTransportControls().sendCustomAction(ACTION_RESUME_BY_AUDIO_FOCUS, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,6 +225,14 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
Log.d(LOGTAG, "Controller, onStart");
|
||||
notifyControlInterfaceChanged(ACTION_PAUSE);
|
||||
mActionState = ACTION_RESUME;
|
||||
} else if (action.equals(ACTION_PAUSE_BY_AUDIO_FOCUS)) {
|
||||
Log.d(LOGTAG, "Controller, pause by audio focus changed");
|
||||
notifyControlInterfaceChanged(ACTION_RESUME);
|
||||
mActionState = ACTION_PAUSE_BY_AUDIO_FOCUS;
|
||||
} else if (action.equals(ACTION_RESUME_BY_AUDIO_FOCUS)) {
|
||||
Log.d(LOGTAG, "Controller, resume by audio focus changed");
|
||||
notifyControlInterfaceChanged(ACTION_PAUSE);
|
||||
mActionState = ACTION_RESUME_BY_AUDIO_FOCUS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,6 +243,8 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
notifyControlInterfaceChanged(ACTION_PAUSE);
|
||||
notifyObservers("MediaControl", "resumeMedia");
|
||||
mActionState = ACTION_RESUME;
|
||||
// To make sure we always own audio focus during playing.
|
||||
AudioFocusAgent.notifyStartedPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -236,6 +254,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
notifyControlInterfaceChanged(ACTION_RESUME);
|
||||
notifyObservers("MediaControl", "mediaControlPaused");
|
||||
mActionState = ACTION_PAUSE;
|
||||
AudioFocusAgent.notifyStoppedPlaying();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user