just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

Please add the "android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" to the readme

Open evsXez opened this issue 2 years ago • 3 comments

To which pages does your suggestion apply?

  • https://pub.dev/packages/just_audio_background#android-setup

Quote the sentences(s) from the documentation to be improved (if any)

<!-- ADD THESE TWO PERMISSIONS --> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

Describe your suggestion

As documented in https://developer.android.com/guide/components/foreground-services#request-foreground-service-permissions apps that target Android 14 (API level 34) "must request the appropriate permission type". Otherwise we will get in production such error messages:

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Starting FGS with type mediaPlayback callerApp=ProcessRecord{a0ac00f 14173: ...} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK] , null, java.lang.SecurityException: Starting FGS with type mediaPlayback callerApp=ProcessRecord{a0ac00f 14173:...} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_ ...

Failing to do it will not prevent the actual playing in foreground/background states in Android 14. But the foreground service will not be started properly. This will lead to a bad state: playback can continue in the background but no notification will be shown and the app could be (and will if the user will open/run other applications) closed by the Android system due to the process of freeing up memory.

Simply you need to change this to prevent such situation.

<!-- ADD THESE THREE PERMISSIONS --> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>

as shown in https://developer.android.com/about/versions/14/changes/fgs-types-required to start foreground service in Android 14 properly.

P.S.: great lib, many thanks to you and your patience. Good luck in every life's aspect)

evsXez avatar Dec 12 '23 18:12 evsXez

Thanks for pointing this out. The just_audio_background README section was copied from the audio_service README section and so it lags behind it a bit. Can you review the corresponding section on this page and tell me if you would be fine once it's copied across?

https://github.com/ryanheise/audio_service/tree/minor/audio_service

ryanheise avatar Dec 13 '23 01:12 ryanheise

Sure, looks good. It's fine to copy. Also readme (regarding this API level 34) in https://pub.dev/packages/audio_service is outdated. I don't know whether it is needed to publish README on pub.dev manually

evsXez avatar Dec 13 '23 12:12 evsXez

I was linking to the GitHub page since that is where the development version is. This is what will appear in the next release but it hasn't been released yet. As per your review, I will copy this across to just_audio_background.

ryanheise avatar Dec 13 '23 12:12 ryanheise

Completed (although not yet published).

ryanheise avatar Feb 29 '24 15:02 ryanheise

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

github-actions[bot] avatar Mar 15 '24 00:03 github-actions[bot]