suragch / flutter_audio_service_demo

Companion project for Flutter audio_service tutorial
https://suragch.medium.com/background-audio-in-flutter-with-audio-service-and-just-audio-3cce17b4a7d?sk=0837a1b1773e27a4f879ff3072e90305
MIT License
57 stars 28 forks source link

Killing the audio player app should also kill the audio and notification #2

Closed NaagAlgates closed 3 years ago

NaagAlgates commented 3 years ago

Hello @ryanheise, Thank you for your amazing work.

Possible Bug / A question:

To Reproduce Steps to reproduce the behavior:

Expected behavior Ideally, the notification should be removed and the audio should stop playing on killing the main app.

Minimal reproduction project Code to reproduce: https://github.com/suragch/flutter_audio_service_demo

audio_service version: 0.18

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.1, on macOS 11.4 20F71 darwin-x64, locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.58.2)
[✓] Connected device (3 available)

Device: Moto G, Pixel 3XL Android version: 7, 11

Screenshot: image image image

If there is a solution already, please excuse and request you to share the link or minimal code.

suragch commented 3 years ago

Did you mean to open this issue on the audio_service repo?

NaagAlgates commented 3 years ago

Yes. :)

gOzaru commented 2 years ago

Add this code below inside main.dart

  @override
  void dispose() {
    _audioHandler.customAction("dispose");
    super.dispose();
  }

  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.paused) {
      _audioHandler.stop();
    }
  }