Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
On iOS, MediaElement starts or resumes playback at 1x whenever it calls AVPlayer.Play(), regardless of MediaElement.Speed. Speed keeps reporting the requested value, so the property and the actual playback rate disagree.
Measured on main (c8740a8), iPhone 17 simulator, iOS 26.5, with a 24.87s local MP4 (the loop row uses a 3.89s MP3):
| Scenario | Speed reports |
Actual playback |
|---|---|---|
ShouldAutoPlay = false, Speed = 2, then Play() |
2 | 1x (position 2.81s after 3s) |
Playing at Speed = 2, then Pause() and Play() |
2 | 1x (1.91s of media in 2s) |
Playing at Speed = 2, then Stop() and Play() |
2 | 1x (1.83s after 2s) |
ShouldAutoPlay = true with Speed = 2 set before loading |
2 | 1x (1.76s after 2s) |
ShouldLoopPlayback = true, Speed = 2, after the first loop |
2 | 1x (each loop takes about 4s) |
There are two causes:
MediaManager.macios.cscallsPlayer.Play()inPlatformPlay, in the auto-play path ofPlatformUpdateSourceand inPlayedToEnd(looping).AVPlayer.Play()starts playback at a rate of 1, and nothing reappliesMediaElement.Speed.MediaManager.AreFloatingPointNumbersEqualis inverted. It returnsMath.Abs(number1 - number2) > tolerance, which istruewhen the numbers are different.RateChangedinMediaManager.macios.csguards on!AreFloatingPointNumbersEqual(MediaElement.Speed, Player.Rate), so it only assignsMediaElement.Speed = Player.Ratewhen the two are already equal. The player's rate is therefore never synced back toSpeed, which is whySpeedkeeps reporting 2 above.
The inverted helper also affects Android:
OnPlaybackParametersChangedinMediaManager.android.csreturns when the speeds differ and assigns only when they are equal, so it never updatesSpeed.PlatformUpdateShouldMuteonly refreshesvolumeBeforeMutewhen it already equalsPlayer.Volume. AVolumeset before the handler connects is lost: on an Android 17 emulator, aMediaElementcreated withVolume = 0.3reportsVolume1.00 once playing.
Windows is not affected: OnPlaybackSessionPlaybackRateChanged calls the helper without negation, so it behaves correctly given the inverted result.
Expected Behavior
Play(), auto-play and loop restarts play atMediaElement.Speedon iOS and Mac Catalyst.AreFloatingPointNumbersEqualreturnstruewhen the numbers are within the tolerance.- A
Volumeset before the handler connects is kept on Android.
Steps To Reproduce
- Add a
MediaElementwithShouldAutoPlay="False",Speed="2"and a video source. - Run on iOS and wait for the media to load.
- Call
mediaElement.Play(). - Compare
Positionwith elapsed time: it advances at 1x, whileSpeedstill reads 2.
var mediaElement = new MediaElement
{
ShouldAutoPlay = false,
Speed = 2,
Source = MediaSource.FromResource("AppleVideo.mp4")
};
// after the media has loaded
mediaElement.Play();
// 3 seconds later: mediaElement.Position is about 3s (expected about 6s), mediaElement.Speed is 2Link to public reproduction project repository
https://github.com/CommunityToolkit/Maui
There is no separate reproduction repository. The numbers above come from a small test app that references CommunityToolkit.Maui.MediaElement from main and runs the snippet in Steps To Reproduce, using the AppleVideo.mp4 resource from the sample app.
Environment
- .NET MAUI CommunityToolkit: main (c8740a8)
- OS: iOS 26.5 (iPhone 17 simulator); Android 17 emulator for the Volume finding
- .NET MAUI: 10.0.90
- .NET SDK: 10.0.401
- Xcode: 26.6Anything else?
Not verified: Mac Catalyst (same code as iOS, not run) and a physical device.
Related: #1668 reported the same symptom for Play() on iOS and was closed as completed.
Activity
Apply MediaElement.Speed when playback starts on iOS and fix inverted…