Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 3a747bee7ac465555eeb2a943b44e51ee717e777
https://github.com/WebKit/WebKit/commit/3a747bee7ac465555eeb2a943b44e51ee717e777
Author: Eric Carlson <[email protected]>
Date: 2026-01-09 (Fri, 09 Jan 2026)
Changed paths:
M Source/WebCore/Modules/webaudio/AudioContext.cpp
M Source/WebCore/html/HTMLMediaElement.cpp
M Source/WebCore/html/MediaElementSession.cpp
M Source/WebCore/platform/audio/MediaSessionManagerInterface.h
M Source/WebCore/platform/audio/NowPlayingInfo.h
M Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h
M Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
M Source/WebCore/platform/graphics/MediaSourcePrivate.cpp
M
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
M
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
M
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
M
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
M Source/WebCore/testing/Internals.cpp
M Source/WebCore/testing/Internals.h
M Source/WebCore/testing/Internals.idl
M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h
M Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
M Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm
M Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html
Log Message:
-----------
[Cocoa] Only update NowPlaying when playback state changes
https://bugs.webkit.org/show_bug.cgi?id=305170
rdar://166578429
Reviewed by Jean Yves Avenard.
Updating NowPlaying is a relatively expensive operation, so only do it when a
property
it uses other than current time has changed since the last time it was called.
Because it
is important to update NowPlaying with the current time periodically so it's
interpolated
time doesn't drift from the actual playback time, update it even if only
current time
has changed every five seconds.
Add a new API test to verify the changes.
Tests: Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html
* Source/WebCore/Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::nowPlayingInfo const): Initialize
NowPlayingInfo.updateTime.
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged): Call
MediaSessionManager::clientCharacteristicsChanged
when the current playback position reaches the end so we update NowPlaying with
the
state change.
* Source/WebCore/html/MediaElementSession.cpp:
(WebCore::MediaElementSession::computeNowPlayingInfo const): Initialize
NowPlayingInfo.updateTime.
Drive-by fix: use the actual playback rate, not just 1.0
(WebCore::MediaElementSession::clientCharacteristicsChanged): Update NowPlaying
if the
playback position has changed.
* Source/WebCore/platform/audio/MediaSessionManagerInterface.h:
* Source/WebCore/platform/audio/NowPlayingInfo.h: Add `updateTime` to the
struct for testing.
* Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h:
* Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::MediaSessionManagerCocoa): Initialize the
timer we
use to ensure NowPlaying is updated at least every five seconds.
(WebCore::MediaSessionManagerCocoa::setNowPlayingInfo): Some parts of the code
used
-1 for an NowPlayingInfo.duration, and some used NaN. Use NaN everywhere.
(WebCore::MediaSessionManagerCocoa::shouldUpdateNowPlaying):
(WebCore::MediaSessionManagerCocoa::setNowPlayingUpdateInterval): New, setter
for the
minimum NowPlaying interval so we can shorten it for testings.
(WebCore::MediaSessionManagerCocoa::updateNowPlayingInfo): Return early when
`shouldUpdateNowPlaying`
says nothing interesting has changed.
* Source/WebCore/platform/graphics/MediaSourcePrivate.cpp:
(WebCore::MediaSourcePrivate::setMediaPlayerReadyState): Return early if
readyState hasn't
actually changed to avoid churn.
*
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::didEnd): Drive-by: take current time
as a
parameter so we have the time at which playback ended.
*
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
*
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
*
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::didEnd): Ditto.
(-[WebCoreAVFMovieObserver didEnd:]): Pass AVPlayerItem.currentTime to
`didEnd()` as it won't
be called immediately.
* Source/WebCore/testing/Internals.cpp:
(WebCore::Internals::setNowPlayingUpdateInterval):
* Source/WebCore/testing/Internals.h:
* Source/WebCore/testing/Internals.idl:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _requestActiveNowPlayingSessionInfo:]):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/NowPlayingControlsTests.mm:
(-[NowPlayingTestWebView requestActiveNowPlayingSessionInfo]):
(TestWebKitAPI::TEST(NowPlayingControlsTests, NowPlayingUpdatesThrottled)):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/large-video-test-now-playing.html:
Canonical link: https://commits.webkit.org/305364@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications