Bug 1326114 - Only do duration checking for active-media. r=sebastian, a=gchang
authorAlastor Wu <alwu@mozilla.com>
Thu, 23 Feb 2017 12:13:49 +0800
changeset 376549 2690fd706b25499e45fd489a55adddcfbd9772ce
parent 376548 29f91acdc27ff1f127c194d60b4642fc3284f626
child 376550 3f81626a32601f8f4eccf452d3b83ed11cc4ce87
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1326114
milestone53.0a2
Bug 1326114 - Only do duration checking for active-media. r=sebastian, a=gchang Since we don't want to show the media control for the short sound, so we added the duration checking. And this checking only needs to be run when the media is active, we don't need to check the inactive media. MozReview-Commit-ID: AaVGi77nXJ1
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4475,32 +4475,37 @@ Tab.prototype = {
     return true;
   },
 
   OnHistoryReplaceEntry: function(aIndex) {
     // we don't do anything with this, so don't propogate it
     // for now anyway.
   },
 
-  ShouldNotifyMediaPlaybackChange: function(inactive) {
-    // We don't want to show the media control interface for the short sound
-    // which duration is smaller than the threshold. The basic unit is second.
+  ShouldNotifyMediaPlaybackChange: function(activeState) {
+    // If the media is active, we would check it's duration, because we don't
+    // want to show the media control interface for the short sound which
+    // duration is smaller than the threshold. The basic unit is second.
     // Note : the streaming format's duration is infinite.
+    if (activeState === "inactive") {
+      return true;
+    }
+
     const mediaDurationThreshold = 1.0;
 
     let audioElements = this.browser.contentDocument.getElementsByTagName("audio");
     for (let audio of audioElements) {
-      if (audio.paused == inactive && audio.duration < mediaDurationThreshold) {
+      if (!audio.paused && audio.duration < mediaDurationThreshold) {
         return false;
       }
     }
 
     let videoElements = this.browser.contentDocument.getElementsByTagName("video");
     for (let video of videoElements) {
-      if (video.paused == inactive && video.duration < mediaDurationThreshold) {
+      if (!video.paused && video.duration < mediaDurationThreshold) {
         return false;
       }
     }
 
     return true;
   },
 
   observe: function(aSubject, aTopic, aData) {
@@ -4526,24 +4531,23 @@ Tab.prototype = {
           return;
         }
 
         let winId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
         if (this.browser.outerWindowID != winId) {
           return;
         }
 
-        let isInactive = (aData === "inactive");
-        if (!this.ShouldNotifyMediaPlaybackChange(isInactive)) {
+        if (!this.ShouldNotifyMediaPlaybackChange(aData)) {
           return;
         }
 
         let status;
         if (aTopic == "media-playback") {
-          status = isInactive ? "end" : "start";
+          status = (aData === "inactive") ? "end" : "start";
         } else if (aTopic == "media-playback-resumed") {
           status = "resume";
         }
 
         GlobalEventDispatcher.sendRequest({
           type: "Tab:MediaPlaybackChange",
           tabID: this.id,
           status: status