Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

ForegroundServiceStartNotAllowedException

Open Ilyosxon2721 opened this issue 3 years ago • 6 comments

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);
    },
  ),
);

Ilyosxon2721 avatar Aug 07 '22 07:08 Ilyosxon2721

I met some equipment resumeOthersPlayersAfterDone android = true not to take effect

ZhangZhiH avatar Oct 17 '22 05:10 ZhangZhiH

Any solution?

samatzp avatar Feb 16 '23 07:02 samatzp

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>

akarapetsas avatar May 19 '23 17:05 akarapetsas

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.

Sanam-Gurung avatar Aug 31 '23 05:08 Sanam-Gurung

What is your android version ?

kalismeras61 avatar Aug 31 '23 06:08 kalismeras61

What is your android version ?

android 12, but users with android 12+ are facing this issue repeatedly.

Sanam-Gurung avatar Aug 31 '23 06:08 Sanam-Gurung