florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
740 stars 337 forks source link

Two audio tracks play simultaneously when I close and reopen the app #837

Open MazenCoder opened 2 weeks ago

MazenCoder commented 2 weeks ago

Flutter Version Flutter stable: 3.22.1

Lib Version assets_audio_player: ^3.1.1

Platform (Android / iOS )

Two audio tracks play simultaneously when I close and reopen the app. I tried to call the stop() method, but it didn't work to stop the first track.

Future<List<StationModel>> onInitApp() async {

    bool isPlaying = audioPlayer.isPlaying.value;
    if (isPlaying) await audioPlayer.stop();

    final repository = ref.watch(radioRepositoryProvider);
    final result = await repository.getHistorys(stations);
    return result.fold((l) => throw l.message, (r) async {
      Box<dynamic> settings = Boxes.settings();
      int lastIndex = settings.get(Keys.lastIndex, defaultValue: 0);
      List<Audio> audios = _stationToMediaItem(r);
      await audioPlayer.open(
        Playlist(
          audios: audios,
          startIndex: lastIndex,
        ),
        showNotification: true,
        autoStart: true,
      );
      return r;
    });
  }