-
Notifications
You must be signed in to change notification settings - Fork 493
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
When a MediaElement is configured to silently autoplay video (ShouldAutoPlay="True", ShouldMute="True"), the underlying iOS AVPlayer still activates the shared AVAudioSession with CategoryPlayback. This causes the iOS audio session to be stolen, even though the MediaElement produces no audible output.
The effect is that any audio playing from another source (e.g. Spotify, Apple Music, a podcast app) is interrupted or paused whenever the muted MediaElement begins playback.
This is a platform-level side effect of how AVAudioSession works on iOS. Setting the category to Playback and activating the session is a way to indicate that my app intends to be the primary audio source.
Expected Behavior
When a MediaElement is configured to play silently (muted or zero volume), it should not interrupt or claim exclusive ownership of the iOS audio session. Ideally, the MediaElement (or its platform view) should either:
- Use
AVAudioSessionCategory.Ambient(orPlaybackwith the.MixWithOthersoption) when the media is muted, so that other audio sources are not interrupted. - Expose a configurable property (e.g.
AudioSessionCategoryorAudioMixBehavior) that allows the developer to control theAVAudioSessioncategory used by eachMediaElementinstance. - Provide a way to pass audio session configuration through
ToPlatformViewor via theMauiMediaElementconstructor on iOS/macOS, so that developers can influence theAVAudioSessionsetup at the platform level.
Option 3 would be the most flexible, as it would allow developers to handle their own use-case-specific audio session management without the toolkit needing to anticipate every scenario.
Steps To Reproduce
- Create a .NET MAUI application targeting iOS.
- Add a single
MediaElementto a page, configured to autoplay muted:
<toolkit:MediaElement
Source="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
ShouldAutoPlay="True"
ShouldMute="True"
ShouldShowPlaybackControls="False"
Aspect="AspectFill"
HeightRequest="300" />- Before opening the app, start playing audio from another app (e.g. Spotify or Apple Music).
- Launch the MAUI app on an iOS device or simulator.
- Observe that the background audio is interrupted/paused as the muted
MediaElementbegins autoplay.
There's a reproduction project repo linked below too.
Link to public reproduction project repository
https://github.com/Joeb454/maui-media-element-repro
Environment
- **CommunityToolkit.Maui.MediaElement**: 8.0.0
- **OS**: iOS 18.x (also reproducible on earlier iOS versions)
- **.NET MAUI**: 10.xAnything else?
The root of the issue appears to be in MediaManager.macios.cs, where the AVAudioSession is configured during player setup. Currently there is no mechanism to influence the audio session category from the MediaElement API or to pass configuration through to the platform view.