-
Notifications
You must be signed in to change notification settings - Fork 380
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
Getting ForegroundServiceStartNotAllowedException #111
Comments
I can see you also filed #112 which looks related. I'll ask some information here to understand the usage of MediaSessionService in your app before going to #112. Can you share how you're using
For context: The stack trace shows that the player started playback while the service was not on the foreground anymore. Playback may start
You mention that you |
I can reliably reproduce this issue by starting playback with the media controls of my smartwatch. (Android 12, Oneplus 6T) Smartwatch is a Garmin Vivoactive 4. |
@christosts Thanks for the questions! They're very inspiring in many ways, I'll also recheck how those situations were handled in your sample app. Here's how we implemented our playback service, please kindly check: We're using it for audio playlist streaming and local audio file playback, the Regarding your questions:
We didn't override the method that related to notification posting.
No, is it required to get media playback working without issue? 🤔
I assume that starting the playback from the notification in the background was already handled on your side, and we didn't override that functionality. As I see, the media controller creation is asynchronous, we do create it when the app is in the foreground, but I'm suspecting it may have a chance to be finished in the background, what's your thought on this?
This crash only happens on Android 12 according to our stats.
Actually no, I saw that the |
Thank you for your answers. My questions were for trying to understand how you are using the Starting playback from notifications in the background is handled by the library. We haven't spotted a bug (yet) but maybe we missed something. I looked at the code you shared (thanks again!). I noticed you have deviated from the reference service implementation. I wonder if that is causing some of the issues. Some suggestions/questions:
In our reference implementation, the player lifetime coincides with the service lifetime, i.e. the player is created in the service's You also override |
@christosts Yeah, I think the player lifetime is a potential issue as you said, it was designed this way because we wanted to have a global listener attached to the player, so the player UI can react accordingly. I'll have a deeper look at your sample project and see how we can adjust it to fit our requirements, huge thanks for the suggestions!
We want to stop the playback when the app is removed from the recent activities, so that's why we call |
It makes sense. Overall, my recommendation remains to start by releasing the player in the service's onDestroy(). For example, right now, calling Back to the exception/stack trace now: the issue is that the player started playback while the app/service are not in the foreground. If playback started from notification, then the play button in the notifications starts the service in the foreground. The question then is if our app started playback from another source (see comment below) |
@kevinguitar & @chvp we know of a use-case where this error is being raised, when playback is started from other apps connected through MediaSession, i.e. playback did not start as a result of a notification posted by the library, specifically on Android 12. We're working on this use-case and I'll update the issue for any findings/solution/advice. |
Has there been any update? I've got a similar stacktrace:
|
Is this issue fixed in the 1.0.0-beta03 version ? |
Have you tried? If you are still seeing this, please expand your comment to make it actionable. Check my response to your comment in the other issue. We need the same details from you as I have explained there. |
I assumed from this comment that it was clear what the issue is: #111 (comment) |
I released my app with beta03 and so far I haven't gotten anything. So could be fixed or no one has ran into that particular issue. Gut feeling tells me it's better though. |
Thanks @vannitech for the update. Please post here if you see something else!
Yeah, not sure I'm afraid. It's quite a jungle with API levels and targetSdk, so we would need to have all the details. That's why I'm commenting that placing an Some more context. In general for A) On Android 12 there is an issue in the framework that there is no exemption for calls coming through the legacy media session. One of the use case that is broken on these devices and is easy to repro is pausing and resuming playback by voice command. A fix for S has been sent far patching to OEMs. It's on their discretion how to go forward. We have to assume that it never lands on some devices I'm afraid. What is on our plate for these cases is a) that we will catch such exceptions in the library (probably silently) to avoid a crash. We can't it work on the library side unfortunately. We further will b) change the B) The fix mentioned is in Android 13. If someone sees a |
That's clear, thanks. I did not know about the changes to the framework. I can confirm I can no longer repro this issue with my smartwatch on Android 13 (because this issue was not updated, I assumed this wasn't fixed yet, so I didn't try). (This is also the only issue I am subscribed to, so I didn't see any other "is this fixed yet" comments. I get that those can be annoying 🙂.) |
@marcbaechinger I'm getting this crash on Android 13 as well. My case is that user goes to background, listens for around 20 minutes and it crashes when transitioning to other item. Item transition is handled by player (we only provide list of items). |
Summarizing the known causes for
That's the state so far and all I know. |
This is really helpful - thanks @marcbaechinger If useful to others we also are seeing this on Android 12 and 13 only through Crashlytics and cannot (yet) reproduce locally. We are tracking the package IDs that are causing our
|
@marcbaechinger Thank you. When is the next version released ? |
@julianD77 What is 'this' in your case? Is it one of the cases above?
This is expected behaviour. To be precise, these packages will not However, as I said it is expected that the service is created and accessed by the package names you are mentioning. I think though, they are accessing service methods (like |
Thanks @marcbaechinger yes, sorry I was referring to an issue we see when using the For info, we have just tracked down the issue with our Thanks also for the clarification regarding processes accessing binding to the service temporarily for the purpose of retrieving information about the catalogue using |
@marcbaechinger Did you investigate this? |
I'm just getting this, described in #1715 |
I tried it, but it doesn't work. |
Can we get some help on this? In my case, it happens the app plays a playlist while at background or with screen off, of music or podcasts. I detailed my finding in #1715 . With this issue, the app doesn't crash, but without foreground service, it's getting killed after a while. |
Media3 Version
1.0.0-beta01
Devices that reproduce the issue
Samsung Galaxy S10+
Samsung Galaxy S32 5G
Samsung Galaxy A51
OPPO A93
Happened only on Android 12
Devices that do not reproduce the issue
Can't reproduce manually, we got the stats from Crashlytics
Reproducible in the demo app?
Not tested
Reproduction steps
We extended our playback service by your
MediaSessionService
, and according to the crash stats in Crashlytics, the device states were 100% in the background, we actually instantiate the media controller right after the user starts to playback, but I'm not sure what's going on under the hood.Expected result
Since we don't have control over starting the service as foreground, I'm wondering does it make sense to catch the exception on the library side, at least to avoid crashing in this case?
Actual result
Getting the crash below
Media
Nothing particular, just normal audio streaming
Bug Report
adb bugreport
to [email protected] after filing this issue.The text was updated successfully, but these errors were encountered: