Using Android Media controls in System UI, with .Net MAUI

591 Views Asked by At

I'm trying to write a media player in.Net MAUI with the new MediaElement, and so far everything seems okay. The only issues that I'm facing is that there seems to be no support for accessing the Media Controls in the System UI, that the android API supports (see here for an example of what I'm after: https://developer.android.com/media/implement/surfaces/mobile).

All I'm trying to achieve is to display that notification with the information of what's currently being played, and to be able to call methods in my application with the controls on that UI (play, pause, seek, etc.) If anyone could point me in the right direction, it would be greatly appreciated.

I've tried googling, binging and duck-duck go-ing, all to no avail. I haven't been able to find a lead for this issue at all so far, but perhaps I just haven't searched far enough.

Thanks, Oli

2

There are 2 best solutions below

1
Ardin On BEST ANSWER

You can use this package for playing audio and video with some extra features Such as control audio and video from notification bar or lock screen Have queue for musics, play online and...

https://www.nuget.org/packages/Plugin.MediaManager/

I implement a music player with maui and use this package for playing audio

1
Jeremy Richards On

Oli,

I am on a similar journey but you seem to be somewhat ahead of me. I am coming from a Xamarin background and just starting Maui work. This is probably less of an answer and more some direction on your journey.

MediaElement is implemented via ExoPlayer on Android (unclear if Exoplayer2 or 3 yet to me). You might look at the exoplayer documentation. You might need need to customize the Maui handler for Android.

Looking at your linked docs, it looks like you may be responsible to set up an MediaSessionService derived class to link common media controls (play/pause/next track, etc) to commands in your app. I have never tried this in Maui, but doing similar stuff in Xamarin was usually possible, if not always well documented. A quick search doesn't show any Maui examples. If I get to that point in my app before you find an example, I will post what I come up with.