Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAUI Android audio stops after running in the background for about 15 minutes #900

Open
copang opened this issue May 24, 2023 · 6 comments

Comments

@copang
Copy link

copang commented May 24, 2023

I'm using the latest version (1.2.2) for my MAUI app (.net 7) and I'm having problems running it on Android. After the app goes into the background for about 15 minutes the audio stops and when I go back to the app it restarts instead of resuming the current state. I noticed that on the notification manager there is already a player, so I think it has been registered as a service to be able to run in the background.
I tried to build in release mode but the result is the same. And of course I have turned off the battery saving modes on the devices already. The devices I am testing are Xiaomi, One plus (Android 12 & 13).
Also, I accidentally discovered that if the phone is connected to the charging cable (which is charging) the audio can play for hours in the background.

  • Platform: Android (Android 12 & 13)
  • MAUI (.net 7)
  • Plugin.MediaManager 1.2.2
@copang
Copy link
Author

copang commented May 24, 2023

@ArchangelWTF @janwiebe-jump can you help me?

@arahmancsd
Copy link

same here. I noticed the app is crashing/closing after 10-15 mins when the app is in the background/foreground.

@efhayati
Copy link

Same issue here. It woks fine when the phone is charging, but otherwise after 2-3 minutes the audio stops. I'm trying to play an stream.

Platform: Android (Android 13)
MAUI (.net 7)
Plugin.MediaManager 1.2.2

@sandreas
Copy link

sandreas commented Sep 1, 2023

@szurgot
Copy link

szurgot commented Oct 4, 2023

This is happening because the service is never set to Foreground which is due to the initialization of the PlayerNotificationManager is happening incorrectly. The PlayerNotificationManager is being built on line 118. but one of it's parameters isn't is null when it's invoked: https://github.com/Baseflow/XamarinMediaManager/blob/develop/MediaManager/Platforms/Android/MediaSession/MediaBrowserService.cs#L118

Since the NotificationListener is properly constructed on the next line, switching those two lines will resolve the problem.

@ikeremozcan
Copy link

ikeremozcan commented Apr 4, 2024

Android devices has battery optimization settings for the apps. Could you try to get this permission and see that's work for you.
if (Build.VERSION.SdkInt >= BuildVersionCodes.M) { String? packageName = Platform.CurrentActivity?.PackageName; Android.Content.Intent intent = new Android.Content.Intent(); intent.SetAction(Android.Provider.Settings.ActionRequestIgnoreBatteryOptimizations); intent.SetData(Android.Net.Uri.Parse("package:" + packageName)); Platform.CurrentActivity?.StartActivity(intent); }

Also add this to manifest
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants