[iOS] Enable media element volume on iPad
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jan 2019 15:31:02 +0000 (15:31 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Jan 2019 15:31:02 +0000 (15:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193745
<rdar://problem/47452297>

Reviewed by Jer Noble.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setVolume):
(WebCore::HTMLMediaElement::mediaPlayerVolumeChanged):
(WebCore::HTMLMediaElement::updateVolume):

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::setVolume):

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

index 676ce88..afdb6af 100644 (file)
@@ -1,3 +1,19 @@
+2019-01-24  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] Enable media element volume on iPad
+        https://bugs.webkit.org/show_bug.cgi?id=193745
+        <rdar://problem/47452297>
+
+        Reviewed by Jer Noble.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setVolume):
+        (WebCore::HTMLMediaElement::mediaPlayerVolumeChanged):
+        (WebCore::HTMLMediaElement::updateVolume):
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::setVolume):
+
 2019-01-24  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK][WPE] Support JPEG 2000 images
index 5e09f09..82c8be6 100644 (file)
@@ -3712,7 +3712,11 @@ ExceptionOr<void> HTMLMediaElement::setVolume(double volume)
     if (!(volume >= 0 && volume <= 1))
         return Exception { IndexSizeError };
 
-#if !PLATFORM(IOS_FAMILY)
+#if PLATFORM(IOS_FAMILY)
+    if (!processingUserGestureForMedia())
+        return { };
+#endif
+
     if (m_volume == volume)
         return { };
 
@@ -3728,7 +3732,7 @@ ExceptionOr<void> HTMLMediaElement::setVolume(double volume)
         pauseInternal();
         setAutoplayEventPlaybackState(AutoplayEventPlaybackState::PreventedAutoplay);
     }
-#endif
+
     return { };
 }
 
@@ -4919,9 +4923,9 @@ void HTMLMediaElement::mediaPlayerVolumeChanged(MediaPlayer*)
 
     beginProcessingMediaPlayerCallback();
     if (m_player) {
-        double vol = m_player->volume();
-        if (vol != m_volume) {
-            m_volume = vol;
+        double volume = m_player->volume();
+        if (volume != m_volume) {
+            m_volume = volume;
             updateVolume();
             scheduleEvent(eventNames().volumechangeEvent);
         }
@@ -5334,14 +5338,7 @@ void HTMLMediaElement::updateVolume()
 {
     if (!m_player)
         return;
-#if PLATFORM(IOS_FAMILY)
-    // Only the user can change audio volume so update the cached volume and post the changed event.
-    float volume = m_player->volume();
-    if (m_volume != volume) {
-        m_volume = volume;
-        scheduleEvent(eventNames().volumechangeEvent);
-    }
-#else
+
     // Avoid recursion when the player reports volume changes.
     if (!processingMediaPlayerCallback()) {
         Page* page = document().page();
@@ -5370,7 +5367,6 @@ void HTMLMediaElement::updateVolume()
 
     if (hasMediaControls())
         mediaControls()->changedVolume();
-#endif
 }
 
 void HTMLMediaElement::scheduleUpdatePlayState()
index 758c5c4..4a73543 100644 (file)
@@ -305,7 +305,6 @@ SOFT_LINK_OPTIONAL(MediaToolbox, MTEnableCaption2015Behavior, Boolean, (), ())
 #if PLATFORM(IOS_FAMILY)
 
 #if HAVE(CELESTIAL)
-
 SOFT_LINK_PRIVATE_FRAMEWORK(Celestial)
 SOFT_LINK_CONSTANT(Celestial, AVController_RouteDescriptionKey_RouteCurrentlyPicked, NSString *)
 SOFT_LINK_CONSTANT(Celestial, AVController_RouteDescriptionKey_RouteName, NSString *)
@@ -313,7 +312,6 @@ SOFT_LINK_CONSTANT(Celestial, AVController_RouteDescriptionKey_AVAudioRouteName,
 #define AVController_RouteDescriptionKey_RouteCurrentlyPicked getAVController_RouteDescriptionKey_RouteCurrentlyPicked()
 #define AVController_RouteDescriptionKey_RouteName getAVController_RouteDescriptionKey_RouteName()
 #define AVController_RouteDescriptionKey_AVAudioRouteName getAVController_RouteDescriptionKey_AVAudioRouteName()
-
 #endif // HAVE(CELESTIAL)
 
 #endif // PLATFORM(IOS_FAMILY)
@@ -1382,14 +1380,14 @@ void MediaPlayerPrivateAVFoundationObjC::seekToTime(const MediaTime& time, const
 void MediaPlayerPrivateAVFoundationObjC::setVolume(float volume)
 {
 #if PLATFORM(IOS_FAMILY)
-    UNUSED_PARAM(volume);
-    return;
-#else
+    if ([[PAL::getUIDeviceClass() currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad)
+        return;
+#endif
+
     if (!m_avPlayer)
         return;
 
     [m_avPlayer.get() setVolume:volume];
-#endif
 }
 
 void MediaPlayerPrivateAVFoundationObjC::setMuted(bool muted)