[iOS] HTMLMediaSession should set AudioSession category
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jan 2014 21:36:17 +0000 (21:36 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jan 2014 21:36:17 +0000 (21:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127137

Reviewed by Sam Weinig.

* html/HTMLMediaSession.cpp:
(WebCore::initializeAudioSession): New, set the audio session to "media" on iOS.
(WebCore::HTMLMediaSession::HTMLMediaSession): Call initializeAudioSession.

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaSession.cpp

index 79204a923eb08db887e4d15b241ae6b6cbb2cb67..1a200040ff9106838a81a7400aace96993182033 100644 (file)
@@ -1,3 +1,14 @@
+2014-01-17  Eric Carlson  <eric.carlson@apple.com>
+
+        [iOS] HTMLMediaSession should set AudioSession category
+        https://bugs.webkit.org/show_bug.cgi?id=127137
+
+        Reviewed by Sam Weinig.
+
+        * html/HTMLMediaSession.cpp:
+        (WebCore::initializeAudioSession): New, set the audio session to "media" on iOS.
+        (WebCore::HTMLMediaSession::HTMLMediaSession): Call initializeAudioSession.
+
 2014-01-17  Daniel Bates  <dabates@apple.com>
 
         Fix the iOS build after <http://trac.webkit.org/changeset/162178>
index 36c21b1136e401b64c56c899440e496bbfe12363..2fd037fdf913cbd0048195d9fdf0cc7fd15f89ab 100644 (file)
 #include "ScriptController.h"
 
 #if PLATFORM(IOS)
+#include "AudioSession.h"
 #include "RuntimeApplicationChecksIOS.h"
 #endif
 
 namespace WebCore {
 
+static void initializeAudioSession()
+{
+#if PLATFORM(IOS)
+    static bool wasAudioSessionInitialized;
+    if (wasAudioSessionInitialized)
+        return;
+
+    wasAudioSessionInitialized = true;
+    if (!WebCore::applicationIsMobileSafari())
+        return;
+
+    AudioSession::sharedSession().setCategory(AudioSession::MediaPlayback);
+#endif
+}
+
 std::unique_ptr<HTMLMediaSession> HTMLMediaSession::create(MediaSessionClient& client)
 {
     return std::make_unique<HTMLMediaSession>(client);
@@ -50,6 +66,7 @@ HTMLMediaSession::HTMLMediaSession(MediaSessionClient& client)
     : MediaSession(client)
     , m_restrictions(NoRestrictions)
 {
+    initializeAudioSession();
 }
 
 void HTMLMediaSession::addBehaviorRestriction(BehaviorRestrictions restriction)
@@ -99,7 +116,7 @@ bool HTMLMediaSession::pageAllowsDataLoading(const HTMLMediaElement& element) co
         LOG(Media, "HTMLMediaSession::pageAllowsDataLoading - returning FALSE");
         return false;
     }
-    
+
     return true;
 }
 
@@ -110,7 +127,7 @@ bool HTMLMediaSession::pageAllowsPlaybackAfterResuming(const HTMLMediaElement& e
         LOG(Media, "HTMLMediaSession::pageAllowsPlaybackAfterResuming - returning FALSE");
         return false;
     }
-    
+
     return true;
 }
 
@@ -121,7 +138,7 @@ bool HTMLMediaSession::showingPlaybackTargetPickerPermitted(const HTMLMediaEleme
         LOG(Media, "HTMLMediaSession::showingPlaybackTargetPickerPermitted - returning FALSE");
         return false;
     }
-    
+
     return true;
 }
 #endif