Title: [289942] trunk/Source/WebCore
Revision
289942
Author
[email protected]
Date
2022-02-16 12:22:40 -0800 (Wed, 16 Feb 2022)

Log Message

[Cocoa] Update audio session category before setting NowPlaying status
https://bugs.webkit.org/show_bug.cgi?id=236620
rdar://88827167

Reviewed by Jer Noble.

NowPlaying doesn't update correctly when the audio category changes from Ambient
to Playback after becoming active, so always set the category first.

Tested manually.

* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::clientWillBeginPlayback): Set "preparingToPlay"
before calling `sessionWillBeginPlayback` so `updateSessionState` can tell that
playback is about to begin.
* platform/audio/PlatformMediaSession.h:

* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::updateSessionState): Consider a session to
potentially have audio if it is preparing to play.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289941 => 289942)


--- trunk/Source/WebCore/ChangeLog	2022-02-16 20:16:25 UTC (rev 289941)
+++ trunk/Source/WebCore/ChangeLog	2022-02-16 20:22:40 UTC (rev 289942)
@@ -1,3 +1,26 @@
+2022-02-16  Eric Carlson  <[email protected]>
+
+        [Cocoa] Update audio session category before setting NowPlaying status
+        https://bugs.webkit.org/show_bug.cgi?id=236620
+        rdar://88827167
+
+        Reviewed by Jer Noble.
+
+        NowPlaying doesn't update correctly when the audio category changes from Ambient
+        to Playback after becoming active, so always set the category first.
+
+        Tested manually.
+
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::clientWillBeginPlayback): Set "preparingToPlay"
+        before calling `sessionWillBeginPlayback` so `updateSessionState` can tell that
+        playback is about to begin.
+        * platform/audio/PlatformMediaSession.h:
+
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (WebCore::MediaSessionManagerCocoa::updateSessionState): Consider a session to 
+        potentially have audio if it is preparing to play.
+
 2022-02-16  Kimmo Kinnunen  <[email protected]>
 
         ANGLE includes interfere with system header includes

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp (289941 => 289942)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2022-02-16 20:16:25 UTC (rev 289941)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.cpp	2022-02-16 20:22:40 UTC (rev 289942)
@@ -32,6 +32,7 @@
 #include "MediaPlayer.h"
 #include "NowPlayingInfo.h"
 #include "PlatformMediaSessionManager.h"
+#include <wtf/SetForScope.h>
 
 namespace WebCore {
 
@@ -235,6 +236,8 @@
 
     ALWAYS_LOG(LOGIDENTIFIER, "state = ", m_state);
 
+    SetForScope<bool> preparingToPlay(m_preparingToPlay, true);
+
     if (!PlatformMediaSessionManager::sharedManager().sessionWillBeginPlayback(*this)) {
         if (state() == Interrupted)
             m_stateToRestore = Playing;

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (289941 => 289942)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2022-02-16 20:16:25 UTC (rev 289941)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2022-02-16 20:22:40 UTC (rev 289942)
@@ -187,6 +187,8 @@
     bool hasPlayedSinceLastInterruption() const { return m_hasPlayedSinceLastInterruption; }
     void clearHasPlayedSinceLastInterruption() { m_hasPlayedSinceLastInterruption = false; }
 
+    bool preparingToPlay() const { return m_preparingToPlay; }
+
 #if !RELEASE_LOG_DISABLED
     const Logger& logger() const final { return m_logger.get(); }
     const void* logIdentifier() const override { return m_logIdentifier; }
@@ -225,6 +227,7 @@
     bool m_notifyingClient { false };
     bool m_isPlayingToWirelessPlaybackTarget { false };
     bool m_hasPlayedSinceLastInterruption { false };
+    bool m_preparingToPlay { false };
 
 #if !RELEASE_LOG_DISABLED
     Ref<const Logger> m_logger;

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (289941 => 289942)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-02-16 20:16:25 UTC (rev 289941)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2022-02-16 20:22:40 UTC (rev 289942)
@@ -125,7 +125,10 @@
         }
 
         if (!hasAudibleAudioOrVideoMediaType) {
-            bool isPotentiallyAudible = session.isPlayingToWirelessPlaybackTarget() || ((type == PlatformMediaSession::MediaType::VideoAudio || type == PlatformMediaSession::MediaType::Audio) && session.canProduceAudio() && session.hasPlayedSinceLastInterruption());
+            bool isPotentiallyAudible = session.isPlayingToWirelessPlaybackTarget()
+                || ((type == PlatformMediaSession::MediaType::VideoAudio || type == PlatformMediaSession::MediaType::Audio)
+                    && session.canProduceAudio()
+                    && (session.hasPlayedSinceLastInterruption() || session.preparingToPlay()));
             if (isPotentiallyAudible) {
                 hasAudibleAudioOrVideoMediaType = true;
                 isPlayingAudio |= session.isPlaying();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to