Bug 1284387 - Remove audio control notification after playing tab has been closed. r=ahunt
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 21 Jul 2016 15:33:48 +0200
changeset 331350 a735cdff3c900219b00cd7a683e363be9d6562bc
parent 331349 05b9ca6b58ec97e6e73941831fe7a881cb70bcd3
child 331351 90370c9e5d434cce0b38d27ad907688e9350676a
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt
bugs1284387
milestone50.0a1
Bug 1284387 - Remove audio control notification after playing tab has been closed. r=ahunt MozReview-Commit-ID: 9nrlKpcedzQ
mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
--- 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) {