Bug 1311245 - part1 : don't need to dispatch event to gecko again when receving tab event 'MEDIA_PLAYING_CHANGE' and 'CLOSED'. draft
authorAlastor Wu <alwu@mozilla.com>
Thu, 27 Oct 2016 10:11:46 +0800
changeset 430051 0c6e4ea002e67daeb190cda3039df21bd9484873
parent 430042 3f4c3a3cabaf94958834d3a8935adfb4a887942d
child 430052 76ae47e87f8e0178d390efb9bc281449579e0fce
push id33722
push useralwu@mozilla.com
push dateThu, 27 Oct 2016 02:13:11 +0000
bugs1311245
milestone52.0a1
Bug 1311245 - part1 : don't need to dispatch event to gecko again when receving tab event 'MEDIA_PLAYING_CHANGE' and 'CLOSED'. We don't need gecko to do something when receiving 'MEDIA_PLAYING_CHANGE' and 'CLOSED'. The only thing we need to do in Java side is to modify the media control's UI interface. MozReview-Commit-ID: 6NrNraVOixg
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,26 +97,27 @@ public class MediaControlService extends
             return;
         }
 
         final Tab playingTab = mTabReference.get();
         switch (msg) {
             case MEDIA_PLAYING_CHANGE:
                 if (playingTab != tab && tab.isMediaPlaying()) {
                     mTabReference = new WeakReference<>(tab);
-                    mController.getTransportControls().sendCustomAction(ACTION_START, null);
+                    notifyControlInterfaceChanged(ACTION_PAUSE);
                 } else if (playingTab == tab && !tab.isMediaPlaying()) {
-                    mController.getTransportControls().stop();
+                    notifyControlInterfaceChanged(ACTION_STOP);
+                    mTabReference = new WeakReference<>(null);
                 }
                 break;
 
             case CLOSED:
                 if (playingTab == null || playingTab == tab) {
                     // Remove the controls when the playing tab disappeared or was closed.
-                    mController.getTransportControls().stop();
+                    notifyControlInterfaceChanged(ACTION_STOP);
                 }
                 break;
             case FAVICON:
                 if (playingTab == tab) {
                     final String actionForPendingIntent = isMediaPlaying() ?
                         ACTION_PAUSE : ACTION_RESUME;
                     notifyControlInterfaceChanged(actionForPendingIntent);
                 }
@@ -168,17 +169,18 @@ public class MediaControlService extends
         if (intent == null || intent.getAction() == null || !mInitialize) {
             return;
         }
 
         Log.d(LOGTAG, "HandleIntent, action = " + intent.getAction() + ", actionState = " + mActionState);
         switch (intent.getAction()) {
             case ACTION_INIT :
                 // This action is used to create a service and do the initialization,
-                // the actual operation would be executed via tab events.
+                // the actual operation would be executed via control interface's
+                // pending intent.
                 break;
             case ACTION_START :
                 mController.getTransportControls().sendCustomAction(ACTION_START, null);
                 break;
             case ACTION_RESUME :
                 mController.getTransportControls().play();
                 break;
             case ACTION_PAUSE :