1

I initialized my AudioPlayerService

class AudioPlayerService {
  ...
  Future<AudioHandler> initMyAudioHandler() async {
    return await AudioService.init(
      builder: () => MyAudioHandler(),
      config: const AudioServiceConfig(
        androidNotificationChannelId: '...',
        androidNotificationChannelName: 'Audio playback',
        androidNotificationOngoing: true,
        androidStopForegroundOnPause: true,
      ),
    );
  }
  ...
}

I also override some methods inside MyAudioHandler:

  ...
  @override
  Future<void> play() async {
    print('play');
    await _player.play(); // _player is a just_audio instance
  }

  @override
  Future<void> stop() async {
    print('stop');
    await _player.stop();
    await super.stop();
  }

  @override
  Future<void> onNotificationDeleted() async {
    print('notification deleted!'); // DOESN'T TRIGGER
    await super.onNotificationDeleted();
  }
  ...

The basic functions of play, pause and stop work well. But I can't detect when the user has paused the audio from outside the app and swiped the notification away. I assume this would trigger onNotificationDeleted, but it doesn't.

I tested this on the emulator and an actual device running Android 13 (SDK 33), with audio_service: ^0.18.9

Siddharth Mehra
  • 1,691
  • 1
  • 9
  • 32
Edward Cahyadi
  • 450
  • 5
  • 9

0 Answers0