Bug 1322114 - handle more media state change draft
authorJulian_Chu <walkingice0204@gmail.com>
Tue, 10 Jan 2017 13:41:32 +0800
changeset 457901 6c67fa6053f91821b8756e8a5f652bad37e15754
parent 449801 7652a58efa46f1c57c94bba26efc5d53b6184e83
child 541620 389ed0fadfa7302cb9669ae362a6ca902819c082
push id40927
push userbmo:walkingice0204@gmail.com
push dateTue, 10 Jan 2017 05:49:04 +0000
bugs1322114
milestone53.0a1
Bug 1322114 - handle more media state change When the playing media changes, there will be one more event MEDIA_PLAYING_CHANGE, and the tab is still playing media. This fix is to handle this situation then update Notification Bar. MozReview-Commit-ID: DnsvaiLJ7Vw
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
@@ -106,19 +106,23 @@ public class MediaControlService extends
         final Tab playingTab = mTabReference.get();
         switch (msg) {
             case MEDIA_PLAYING_CHANGE:
                 // The 'MEDIA_PLAYING_CHANGE' would only be received when the
                 // media starts or ends.
                 if (playingTab != tab && tab.isMediaPlaying()) {
                     mTabReference = new WeakReference<>(tab);
                     notifyControlInterfaceChanged(ACTION_PAUSE);
-                } else if (playingTab == tab && !tab.isMediaPlaying()) {
-                    notifyControlInterfaceChanged(ACTION_STOP);
-                    mTabReference = new WeakReference<>(null);
+                } else if (playingTab == tab) {
+                    // to understand what action happened in this event
+                    String action = tab.isMediaPlaying() ?  ACTION_RESUME : ACTION_STOP;
+                    // if tab is not playing media, clear reference. Otherwise, keep it.
+                    Tab tabInPlaying = tab.isMediaPlaying() ? tab : null;
+                    notifyControlInterfaceChanged(action);
+                    mTabReference = new WeakReference<>(tabInPlaying);
                 }
                 break;
             case MEDIA_PLAYING_RESUME:
                 // user resume the paused-by-control media from page so that we
                 // should make the control interface consistent.
                 if (playingTab == tab && !isMediaPlaying()) {
                     notifyControlInterfaceChanged(ACTION_PAUSE);
                 }