Bug 1302453 - part2 : notify MediaControlService when the media is resumed. r=sebastian
authorAlastor Wu <alwu@mozilla.com>
Thu, 27 Oct 2016 10:00:25 +0800
changeset 346358 058d1217b0d0d9a9b0cc7d776b6987b7b59bf510
parent 346357 bd09862def55fe93bc681d56397ec6e610d8fe61
child 346359 42d33a2ab63bb176c1e0f4f692d17288654d9519
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1302453
milestone52.0a1
Bug 1302453 - part2 : notify MediaControlService when the media is resumed. r=sebastian When user resumes media from the page, we should notify MediaControlService so that it can change the playing icon to the correct status. MozReview-Commit-ID: 15e2GrxvB6a
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -577,18 +577,23 @@ public class Tabs implements GeckoEventL
                 notifyListeners(tab, TabEvents.RECORDING_CHANGE);
             } else if (event.equals("Tab:StreamStop")) {
                 tab.setRecording(false);
                 notifyListeners(tab, TabEvents.RECORDING_CHANGE);
             } else if (event.equals("Tab:AudioPlayingChange")) {
                 tab.setIsAudioPlaying(message.getBoolean("isAudioPlaying"));
                 notifyListeners(tab, TabEvents.AUDIO_PLAYING_CHANGE);
             } else if (event.equals("Tab:MediaPlaybackChange")) {
-                tab.setIsMediaPlaying(message.getBoolean("active"));
-                notifyListeners(tab, TabEvents.MEDIA_PLAYING_CHANGE);
+                final String status = message.getString("status");
+                if (status.equals("resume")) {
+                    notifyListeners(tab, TabEvents.MEDIA_PLAYING_RESUME);
+                } else {
+                    tab.setIsMediaPlaying(status.equals("start"));
+                    notifyListeners(tab, TabEvents.MEDIA_PLAYING_CHANGE);
+                }
             }
 
         } catch (Exception e) {
             Log.w(LOGTAG, "handleMessage threw for " + event, e);
         }
     }
 
     public void refreshThumbnails() {
@@ -639,16 +644,17 @@ public class Tabs implements GeckoEventL
         SECURITY_CHANGE,
         DESKTOP_MODE_CHANGE,
         RECORDING_CHANGE,
         BOOKMARK_ADDED,
         BOOKMARK_REMOVED,
         AUDIO_PLAYING_CHANGE,
         OPENED_FROM_TABS_TRAY,
         MEDIA_PLAYING_CHANGE,
+        MEDIA_PLAYING_RESUME
     }
 
     public void notifyListeners(Tab tab, TabEvents msg) {
         notifyListeners(tab, msg, "");
     }
 
     public void notifyListeners(final Tab tab, final TabEvents msg, final String data) {
         if (tab == null &&
--- a/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/MediaControlService.java
@@ -95,24 +95,32 @@ public class MediaControlService extends
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
         if (!mInitialize) {
             return;
         }
 
         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);
                     mController.getTransportControls().sendCustomAction(ACTION_START, null);
                 } else if (playingTab == tab && !tab.isMediaPlaying()) {
                     mController.getTransportControls().stop();
                 }
                 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()) {
+                    mController.getTransportControls().play();
+                }
+                break;
             case CLOSED:
                 if (playingTab == null || playingTab == tab) {
                     // Remove the controls when the playing tab disappeared or was closed.
                     mController.getTransportControls().stop();
                 }
                 break;
             case FAVICON:
                 if (playingTab == tab) {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3514,16 +3514,17 @@ Tab.prototype = {
 
     // Note that the XBL binding is untrusted
     this.browser.addEventListener("PluginBindingAttached", this, true, true);
     this.browser.addEventListener("VideoBindingAttached", this, true, true);
     this.browser.addEventListener("VideoBindingCast", this, true, true);
 
     Services.obs.addObserver(this, "before-first-paint", false);
     Services.obs.addObserver(this, "media-playback", false);
+    Services.obs.addObserver(this, "media-playback-resumed", false);
 
     // Always intialise new tabs with basic session store data to avoid
     // problems with functions that always expect it to be present
     this.browser.__SS_data = {
       entries: [{
         url: aURL,
         title: truncate(title, MAX_TITLE_LENGTH)
       }],
@@ -3624,16 +3625,17 @@ Tab.prototype = {
     this.browser.removeEventListener("TabPreZombify", this, true);
 
     this.browser.removeEventListener("PluginBindingAttached", this, true, true);
     this.browser.removeEventListener("VideoBindingAttached", this, true, true);
     this.browser.removeEventListener("VideoBindingCast", this, true, true);
 
     Services.obs.removeObserver(this, "before-first-paint");
     Services.obs.removeObserver(this, "media-playback", false);
+    Services.obs.removeObserver(this, "media-playback-resumed", false);
 
     // Make sure the previously selected panel remains selected. The selected panel of a deck is
     // not stable when panels are removed.
     let selectedPanel = BrowserApp.deck.selectedPanel;
     BrowserApp.deck.removeChild(this.browser);
     BrowserApp.deck.selectedPanel = selectedPanel;
 
     this.browser = null;
@@ -4390,26 +4392,34 @@ Tab.prototype = {
 
           if (contentDocument instanceof Ci.nsIImageDocument) {
             contentDocument.shrinkToFit();
           }
         }
         break;
 
       case "media-playback":
+      case "media-playback-resumed":
         if (!aSubject) {
           return;
         }
 
         let winId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
         if (this.browser.outerWindowID == winId) {
+          let status;
+          if (aTopic == "media-playback") {
+            status = aData === "active" ? "start" : "end";
+          } else if (aTopic == "media-playback-resumed") {
+            status = "resume";
+          }
+
           Messaging.sendRequest({
             type: "Tab:MediaPlaybackChange",
             tabID: this.id,
-            active: aData === "active"
+            status: status
           });
         }
         break;
     }
   },
 
   // nsIBrowserTab
   get window() {