Bug 1284387 - Remove audio control notification after playing tab has been closed. r?ahunt
MozReview-Commit-ID: 9nrlKpcedzQ
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -97,23 +97,33 @@ public class MediaControlService extends
}
@Override
public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
if (!mIsInitMediaSession) {
return;
}
- if (tab == mTabReference.get()) {
- return;
- }
+ switch (msg) {
+ case AUDIO_PLAYING_CHANGE:
+ if (tab == mTabReference.get()) {
+ return;
+ }
- if (msg == Tabs.TabEvents.AUDIO_PLAYING_CHANGE && tab.isAudioPlaying()) {
- mTabReference = new WeakReference<Tab>(tab);
- notifyControlInterfaceChanged(ACTION_PAUSE);
+ mTabReference = new WeakReference<>(tab);
+ notifyControlInterfaceChanged(ACTION_PAUSE);
+ break;
+
+ case CLOSED:
+ final Tab playingTab = mTabReference.get();
+ if (playingTab == null || playingTab == tab) {
+ // The playing tab disappeared or was closed. Remove the controls and stop the service.
+ notifyControlInterfaceChanged(ACTION_REMOVE_CONTROL);
+ }
+ break;
}
}
private boolean isAndroidVersionLollopopOrHigher() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
}
private void handleIntent(Intent intent) {