[iOS] Optimize media controls AirPlay discovery
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 18:12:13 +0000 (18:12 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 18:12:13 +0000 (18:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137180

Reviewed by Darin Adler.

AirPlay discovery mode uses increases power consumption, so don't enable it when there
is no chance an AirPlay target picker will be useful.

* Modules/mediacontrols/mediaControlsiOS.js:
(ControllerIOS): Initialize isListeningForPlaybackTargetAvailabilityEvent.
(ControllerIOS.prototype.addVideoListeners): Don't enable register wireless playback event
    listeners, it isn't possible to show the target picker until there is an inline controller.
(ControllerIOS.prototype.removeVideoListeners): Call setShouldListenForPlaybackTargetAvailabilityEvent.
(ControllerIOS.prototype.setControlsType): Add wireless event listers on when not showing
    the one button controller.
(ControllerIOS.prototype.updateStatusDisplay): Unregister wireless event listeners when the
    media element is in an error state.
(ControllerIOS.prototype.setShouldListenForPlaybackTargetAvailabilityEvent): New, add or
    remove event listeners.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174073 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediacontrols/mediaControlsiOS.js

index d375e76..038758f 100644 (file)
@@ -1,5 +1,27 @@
 2014-09-29  Eric Carlson  <eric.carlson@apple.com>
 
+        [iOS] Optimize media controls AirPlay discovery
+        https://bugs.webkit.org/show_bug.cgi?id=137180
+
+        Reviewed by Darin Adler.
+        
+        AirPlay discovery mode uses increases power consumption, so don't enable it when there
+        is no chance an AirPlay target picker will be useful.
+
+        * Modules/mediacontrols/mediaControlsiOS.js:
+        (ControllerIOS): Initialize isListeningForPlaybackTargetAvailabilityEvent.
+        (ControllerIOS.prototype.addVideoListeners): Don't enable register wireless playback event
+            listeners, it isn't possible to show the target picker until there is an inline controller.
+        (ControllerIOS.prototype.removeVideoListeners): Call setShouldListenForPlaybackTargetAvailabilityEvent.
+        (ControllerIOS.prototype.setControlsType): Add wireless event listers on when not showing 
+            the one button controller.
+        (ControllerIOS.prototype.updateStatusDisplay): Unregister wireless event listeners when the
+            media element is in an error state.
+        (ControllerIOS.prototype.setShouldListenForPlaybackTargetAvailabilityEvent): New, add or
+            remove event listeners. 
+
+2014-09-29  Eric Carlson  <eric.carlson@apple.com>
+
         [iOS] Remove obsolete playbackTargetAvailabilityChanged methods
         https://bugs.webkit.org/show_bug.cgi?id=137179
 
index e47c8d6..42e5f63 100644 (file)
@@ -7,6 +7,7 @@ function ControllerIOS(root, video, host)
 {
     this.hasWirelessPlaybackTargets = false;
     this._pageScaleFactor = 1;
+    this.isListeningForPlaybackTargetAvailabilityEvent = false;
     Controller.call(this, root, video, host);
 
     this.updateWirelessTargetAvailable();
@@ -29,11 +30,6 @@ ControllerIOS.prototype = {
 
         this.listenFor(this.video, 'webkitbeginfullscreen', this.handleFullscreenChange);
         this.listenFor(this.video, 'webkitendfullscreen', this.handleFullscreenChange);
-
-        if (window.WebKitPlaybackTargetAvailabilityEvent) {
-            this.listenFor(this.video, 'webkitcurrentplaybacktargetiswirelesschanged', this.handleWirelessPlaybackChange);
-            this.listenFor(this.video, 'webkitplaybacktargetavailabilitychanged', this.handleWirelessTargetAvailableChange);
-        }
     },
 
     removeVideoListeners: function() {
@@ -42,10 +38,7 @@ ControllerIOS.prototype = {
         this.stopListeningFor(this.video, 'webkitbeginfullscreen', this.handleFullscreenChange);
         this.stopListeningFor(this.video, 'webkitendfullscreen', this.handleFullscreenChange);
 
-        if (window.WebKitPlaybackTargetAvailabilityEvent) {
-            this.stopListeningFor(this.video, 'webkitcurrentplaybacktargetiswirelesschanged', this.handleWirelessPlaybackChange);
-            this.stopListeningFor(this.video, 'webkitplaybacktargetavailabilitychanged', this.handleWirelessTargetAvailableChange);
-        }
+        this.setShouldListenForPlaybackTargetAvailabilityEvent(false);
     },
 
     createBase: function() {
@@ -180,6 +173,8 @@ ControllerIOS.prototype = {
             this.addStartPlaybackControls();
         else
             this.removeStartPlaybackControls();
+
+        this.setShouldListenForPlaybackTargetAvailabilityEvent(type !== ControllerIOS.StartPlaybackControls);
     },
 
     addStartPlaybackControls: function() {
@@ -435,6 +430,8 @@ ControllerIOS.prototype = {
 
     updateStatusDisplay: function(event)
     {
+        if (this.video.error)
+            setShouldListenForPlaybackTargetAvailabilityEvent(false);
         this.controls.startPlaybackButton.classList.toggle(this.ClassNames.failed, this.video.error !== null);
         Controller.prototype.updateStatusDisplay.call(this, event);
     },
@@ -445,6 +442,24 @@ ControllerIOS.prototype = {
         Controller.prototype.setPlaying.call(this, isPlaying);
     },
 
+    setShouldListenForPlaybackTargetAvailabilityEvent: function(shouldListen)
+    {
+        if (!window.WebKitPlaybackTargetAvailabilityEvent || this.isListeningForPlaybackTargetAvailabilityEvent == shouldListen)
+            return;
+
+        if (shouldListen && (this.shouldHaveStartPlaybackButton() || this.video.error))
+            return;
+
+        this.isListeningForPlaybackTargetAvailabilityEvent = shouldListen;
+        if (shouldListen) {
+            this.listenFor(this.video, 'webkitcurrentplaybacktargetiswirelesschanged', this.handleWirelessPlaybackChange);
+            this.listenFor(this.video, 'webkitplaybacktargetavailabilitychanged', this.handleWirelessTargetAvailableChange);
+        } else {
+            this.stopListeningFor(this.video, 'webkitcurrentplaybacktargetiswirelesschanged', this.handleWirelessPlaybackChange);
+            this.stopListeningFor(this.video, 'webkitplaybacktargetavailabilitychanged', this.handleWirelessTargetAvailableChange);
+        }
+    },
+
     get pageScaleFactor() {
         return this._pageScaleFactor;
     },