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


3.Checking code made "boolean startInForegroundRequired = true"

4.Then called the system funtion "ContextCompat.startForegroundService"


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:


Actual result
we got "ForegroundServiceDidNotStartInTimeException & RemoteServiceException" crash in extension class of MediaSessionService:


Media
Not applicable
Bug Report
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
3.Checking code made "boolean startInForegroundRequired = true"
4.Then called the system funtion "ContextCompat.startForegroundService"
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:


Actual result
we got "ForegroundServiceDidNotStartInTimeException & RemoteServiceException" crash in extension class of MediaSessionService:


Media
Not applicable
Bug Report
adb bugreportto android-media-github@google.com after filing this issue.