Skip to content

Positioning "ForegroundServiceDidNotStartInTimeException & RemoteServiceException" of MediaSessionService #1859

@xueluwei1

Description

@xueluwei1

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

Devices: samsung, realme, HUAWEI ...
Android version: 8.1, 9, 10, 11, 12 ...

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

1.Build.VERSION.SDK_INT >= 26
2.Play or some action triggered the "onUpdateNotification" funtion of MediaSessionService class and "updateNotification" funtion of MediaNotificationManager
截屏2024-11-06 15 29 22
截屏2024-11-06 15 33 25
3.Checking code made "boolean startInForegroundRequired = true"
截屏2024-11-06 15 36 03
4.Then called the system funtion "ContextCompat.startForegroundService"
截屏2024-11-06 15 38 26
截屏2024-11-06 15 39 05
5.And an amount of time later, service still running and not completed to call funtion "Util.setForegroundServiceNotification"
6.Finally we got the ForegroundServiceDidNotStartInTimeException on android S or later, and RemoteServiceException on older android versions

Expected result

Expected: You should call "context.startService" instead of "ContextCompat.startForegroundService"

Reason: The "ContextCompat.startForegroundService" funtion calls "startForegroundService" on version 26 and later, so cause these Exceptions. Actually, if you want MediaSessionService be a forground service, just call your "Util.setForegroundServiceNotification" funtion, and start by "context.startService". So that, we will not limited by the "startForegroundService" funtion, and no "ForegroundServiceDidNotStartInTimeException & RemoteServiceException" anymore.

This is the explain:
截屏2024-11-06 16 00 01
截屏2024-11-06 16 02 09

Actual result

we got "ForegroundServiceDidNotStartInTimeException & RemoteServiceException" crash in extension class of MediaSessionService:
截屏2024-11-06 16 12 04
截屏2024-11-06 16 16 25

Media

Not applicable

Bug Report

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions