Repository navigation
Publish a playback rate of 0 to Now Playing while MediaElement is paused on iOS and Mac Catalyst - #3426
Merged
TheCodeTraveler merged 5 commits intoNov 12, 2026
Conversation
…sed on iOS and Mac Catalyst Metadata.SetMetadata published MediaElement.Speed as the Now Playing playback rate whenever the TimeControlStatus of the player changed, including to Paused, so the lock screen and Control Center could show paused media as playing, with the elapsed time advancing. The playback rate is now Speed only while the player plays, and 0 otherwise, both when the metadata is set and when the rate observer publishes the rate. Fixes CommunityToolkit#3383
Collaborator
|
Thanks @marcelomoresco! Could you confirm that this also aligns with the behavior on Android and Windows too? Ideally, we'd want MediaElement's behavior for these to be consistent across all platforms, unless it's not possible on a specific platform:
If it does, could you add Device Tests to demonstrate the behavior is now the same across all platforms if they do not already exist? |
…d Windows The media notification and the lock screen of Android, and the system media overlay of Windows, read the platform media session, which Media3 and the command manager of the MediaPlayer keep up to date: the session plays at the Speed of the MediaElement while the media plays, and is paused while the media is paused (on Android with a playback speed of 0, at the position of the player), as Now Playing now is on iOS and macOS.
…dows media session test fails
…enders or not, and skip the playing one where it doesn't
Contributor
Author
|
Yes, Android and Windows already do this:
Added device tests for both; they pass in CI (the Windows one that needs video playback is skipped there, since the runners don't render video). |
TheCodeTraveler
enabled auto-merge (squash)
November 12, 2026 22:16
TheCodeTraveler
approved these changes
Nov 12, 2026
TheCodeTraveler
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @marcelomoresco! Approved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
On iOS and Mac Catalyst,
Metadata.SetMetadatapublishedMediaElement.Speedas the Now Playing playback rate whenever theTimeControlStatusof the player changed, including toPaused, so the lock screen and Control Center could show paused media as playing, with the elapsed time advancing.The playback rate now follows the player, as suggested in the issue:
SpeedwhileTimeControlStatusisPlaying, and0otherwise (paused, waiting, or stopped), together with the currentElapsedPlaybackTime.Metadatacomputes it in one place, used both bySetMetadataand by the rate observer ofMediaManager(PublishPlaybackRate), so the rate observer can't publishSpeedwhile the player is paused either.Android already behaves this way: the
MediaSessionof the toolkit is a Media3 session of the ExoPlayer, and Media3 publishes the state of the player to the platform media session that the media notification and the lock screen read:STATE_PAUSEDwith a playback speed of 0 and the paused position while the player doesn't play, and the player's speed while it plays. Device tests now check it from the system's side.On Windows, the toolkit leaves the
CommandManagerof itsMediaPlayerenabled, so theMediaPlayermirrors its state into its system media session, which the system media overlay and the lock screen read:Pausedwhile the media is paused, so the overlay doesn't advance the position, with the playback rate of the player, which a pause doesn't change (Windows has a playback status for it). In CI, a pausedMediaElementat aSpeedof 1.5 showedPausedat a rate of 1.5 in its system media session, as its player and itsSystemMediaTransportControlsdid.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
Device tests (
MediaElementApple):MediaManagerSpeedAppleTests.PauseShowsTheMediaAsPausedInNowPlaying: aMediaElementplays at a speed of 1.5, is paused, and Now Playing then has a playback rate of 0 and the current position as its elapsed timeMetadataAppleTests.SetMetadataPublishesTheSpeedAsThePlaybackRateOnlyWhileThePlayerPlays:SetMetadatapublishes the speed while the player plays, and 0 once it's pausedMetadataAppleTests.SetMetadataPublishesTheValuesOfTheMediaElementAndThePlayerItemasserted that the speed (1.5) is published for a player that isn't playing; it now expects 0On an iOS 26.5 simulator, with the tests of
MetadataAppleTestsandMediaManagerSpeedAppleTests:In both runs the test app then stopped with an unhandled
OperationCanceledExceptionthrown from an Objective-C callback, right afterSetMetadataWithoutMediaElementPublishesTheDefaultNowPlayingInfo, so the rest of these classes, including the updatedSetMetadataPublishesTheValuesOfTheMediaElementAndThePlayerItem, didn't run locally. It also happens without this change, so it's not caused by it, and my local setup differs from CI (Xcode 26.6, so the app was built withValidateXcodeVersion=false,MtouchLink=SdkOnlyand the dynamic registrar); theDevice Testscheck runs the whole category with Xcode 27.2.Device tests for Android and Windows:
MediaManagerPlaybackAndroidTests(MediaElementAndroid), reading the platform media session through anandroid.media.session.MediaController:TheMediaSessionPublishesTheSpeedWhileTheMediaPlays: the session plays at a speed of 1.5, then 2 afterSpeedchangesPauseShowsTheMediaAsPausedInTheMediaSession: afterPause(), the session is paused, with a playback speed of 0, at the position of the playerMediaMetadataWindowsTests(MediaMetadataWindows), reading the app's session throughGlobalSystemMediaTransportControlsSessionManager, likeOpenedMediaWithMetadataAppearsAsASystemMediaSession:PauseShowsTheMediaAsPausedInTheSystemMediaSession: afterPause(), the session is paused, at the playback rate of the playerTheSystemMediaSessionPublishesTheSpeedWhileTheMediaPlays: the session plays at a speed of 1.5, then 2. Playing takes a machine that renders the video, so CI skips it, likePlayPauseAndStopCommandsReachTheNativePlayerThe
MediaElementAndroidcategory passed on an Android 10 emulator (321 passed, 2 skipped). I don't have a Windows machine, so the Windows tests ran in CI only.