Skip to content

Publish a playback rate of 0 to Now Playing while MediaElement is paused on iOS and Mac Catalyst - #3426

Merged
TheCodeTraveler merged 5 commits into
CommunityToolkit:mainfrom
marcelomoresco:fix/3383-nowplaying-rate-when-paused
Nov 12, 2026
Merged

TheCodeTraveler merged 5 commits into
CommunityToolkit:mainfrom
marcelomoresco:fix/3383-nowplaying-rate-when-paused

Conversation

@marcelomoresco

@marcelomoresco marcelomoresco commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

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 now follows the player, as suggested in the issue: Speed while TimeControlStatus is Playing, and 0 otherwise (paused, waiting, or stopped), together with the current ElapsedPlaybackTime. Metadata computes it in one place, used both by SetMetadata and by the rate observer of MediaManager (PublishPlaybackRate), so the rate observer can't publish Speed while the player is paused either.

Android already behaves this way: the MediaSession of 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_PAUSED with 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 CommandManager of its MediaPlayer enabled, so the MediaPlayer mirrors its state into its system media session, which the system media overlay and the lock screen read: Paused while 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 paused MediaElement at a Speed of 1.5 showed Paused at a rate of 1.5 in its system media session, as its player and its SystemMediaTransportControls did.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description): not applicable, no API or sample changes
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: not applicable

Additional information

Device tests (MediaElementApple):

  • MediaManagerSpeedAppleTests.PauseShowsTheMediaAsPausedInNowPlaying: a MediaElement plays 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 time
  • MetadataAppleTests.SetMetadataPublishesTheSpeedAsThePlaybackRateOnlyWhileThePlayerPlays: SetMetadata publishes the speed while the player plays, and 0 once it's paused
  • MetadataAppleTests.SetMetadataPublishesTheValuesOfTheMediaElementAndThePlayerItem asserted that the speed (1.5) is published for a player that isn't playing; it now expects 0

On an iOS 26.5 simulator, with the tests of MetadataAppleTests and MediaManagerSpeedAppleTests:

  • without the fix: the two new tests fail (the published rate is 1.5 while paused)
  • with the fix: they pass, and the other tests of both classes that ran pass too (64 passed, 0 failed)

In both runs the test app then stopped with an unhandled OperationCanceledException thrown from an Objective-C callback, right after SetMetadataWithoutMediaElementPublishesTheDefaultNowPlayingInfo, so the rest of these classes, including the updated SetMetadataPublishesTheValuesOfTheMediaElementAndThePlayerItem, 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 with ValidateXcodeVersion=false, MtouchLink=SdkOnly and the dynamic registrar); the Device Tests check runs the whole category with Xcode 27.2.

Device tests for Android and Windows:

  • MediaManagerPlaybackAndroidTests (MediaElementAndroid), reading the platform media session through an android.media.session.MediaController:
    • TheMediaSessionPublishesTheSpeedWhileTheMediaPlays: the session plays at a speed of 1.5, then 2 after Speed changes
    • PauseShowsTheMediaAsPausedInTheMediaSession: after Pause(), the session is paused, with a playback speed of 0, at the position of the player
  • MediaMetadataWindowsTests (MediaMetadataWindows), reading the app's session through GlobalSystemMediaTransportControlsSessionManager, like OpenedMediaWithMetadataAppearsAsASystemMediaSession:
    • PauseShowsTheMediaAsPausedInTheSystemMediaSession: after Pause(), the session is paused, at the playback rate of the player
    • TheSystemMediaSessionPublishesTheSpeedWhileTheMediaPlays: the session plays at a speed of 1.5, then 2. Playing takes a machine that renders the video, so CI skips it, like PlayPauseAndStopCommandsReachTheNativePlayer

The MediaElementAndroid category 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.

…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
@TheCodeTraveler

Copy link
Copy Markdown
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:

  • The lock screen and Control Center show paused media as paused and no time advancing
  • The playback rate now follows the player, as suggested in the issue

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.
…enders or not, and skip the playing one where it doesn't
@marcelomoresco

marcelomoresco commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes, Android and Windows already do this:

  • Android: Media3 publishes STATE_PAUSED with speed 0 while paused, and the player's speed while playing.
  • Windows: the MediaPlayer sets its system media session to Paused (Windows uses that status instead of a rate of 0).

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
TheCodeTraveler enabled auto-merge (squash) November 12, 2026 22:16

@TheCodeTraveler TheCodeTraveler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marcelomoresco! Approved.

@TheCodeTraveler
TheCodeTraveler merged commit 1e0c110 into CommunityToolkit:main Nov 12, 2026
22 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MediaElement on iOS and Mac Catalyst publishes a non-zero playback rate to Now Playing while paused

2 participants