Flutter-AssetsAudioPlayer
Flutter-AssetsAudioPlayer copied to clipboard
ForegroundServiceStartNotAllowedException
3.0.5
My version : 3.0.5
Lib Version
My version :
Android
Platform :
Describe the bug
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.imusic.host/com.github.florent37.assets_audio_player.notification.NotificationService
Small code to reproduce
audioPlayer.open(
Playlist(audios: audioList, startIndex: index),
loopMode: LoopMode.playlist,
showNotification: true,
autoStart: true,
playInBackground: PlayInBackground.enabled,
headPhoneStrategy: HeadPhoneStrategy.pauseOnUnplug,
audioFocusStrategy: const AudioFocusStrategy.request(
resumeAfterInterruption: true,
resumeOthersPlayersAfterDone: true,
),
notificationSettings: NotificationSettings(
stopEnabled: false,
customPlayPauseAction: (player) {
if (audioPlayer.isPlaying.value == true) {
print('True: ${audioPlayer.isPlaying.value}');
audioPlayer.pause();
changeIsPlaying(false);
} else if (audioPlayer.isPlaying.value == false) {
print('False: ${audioPlayer.isPlaying.value}');
audioPlayer.play();
changeIsPlaying(true);
}
},
customStopAction: (player) {
audioPlayer.stop();
audioPlayer.pause();
changeIsPlaying(false);
},
),
);
I met some equipment resumeOthersPlayersAfterDone android = true not to take effect
Any solution?
Add in your manifest the following permissions:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
Also add this service in your manifest too:
<service
tools:node="replace"
android:name=".notification.NotificationService"
android:foregroundServiceType="mediaPlayback"
android:enabled="true"
android:exported="true">
</service>
Add in your manifest the following permissions:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />Also add this service in your manifest too:
<service tools:node="replace" android:name=".notification.NotificationService" android:foregroundServiceType="mediaPlayback" android:enabled="true" android:exported="true"> </service>
Done this but still facing the issue.
What is your android version ?
What is your android version ?
android 12, but users with android 12+ are facing this issue repeatedly.