question

MattiTornio-0868 avatar image
0 Votes"
MattiTornio-0868 asked RobCaplan edited

How to prevent Xamarin Community Toolkit MediaElement from requesting audio focus on Android

Our fitness app uses MediaElement from Xamarin Community Toolkit to play instructional videos. These video files have no audio track but starting to play a video will still pause any music from other apps such as Spotify that is playing in the background. On iOS this is easy to fix but we haven't had any luck on Android yet.

Is there any easy way on Android to prevent Xamarin MediaElement (which is using Android MediaPlayer under the hood) from requesting audio focus when a video file starts playing? None of our videos have audio tracks and we already setting MediaElement's volume to zero, but neither of these fixes our problem.

dotnet-xamarin
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you want to request audio focus when your application play the video files? If so, you can google: Xamarin.Android Audio Focus Request, you can find a article about that, it is achieved by AudioManager

0 Votes 0 ·

No, I specifically don't want the app to request audio focus when a video file starts playing. It appears MediaElement/MediaPlayer does this automatically, even when the video file has no audio track. For our use case this is counterproductive, as we want to display a video file without interfering with any other apps playing music or other audio in the background.

0 Votes 0 ·

I test with other plugin Plugin.MediaManager.Forms to play video, but the background music will be stopped, stop the background music is not achieved by MediaElement, it is android's limiation. Do you use AudioManager to play the background music? If so, you can try to set AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK flag


0 Votes 0 ·

0 Answers