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
757 stars 368 forks source link

RangeError fix #829

Closed rick000 closed 7 months ago

rick000 commented 7 months ago

assets_audio_player.dart

Audio? currentAudio() {
    return audioAt(at: indexList[playlistIndex]);
}

here is my case:

on step 2, when remove last audio in playlist, exception occurred

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
#0      List.[] (dart:core-patch/growable_array.dart:264:36)
#1      _CurrentPlaylist.currentAudio (package:assets_audio_player/src/assets_audio_player.dart:1604:33)
#2      AssetsAudioPlayer._openPlaylistCurrent (package:assets_audio_player/src/assets_audio_player.dart:821:20)
#3      PlayerEditor.onAudioRemovedAt (package:assets_audio_player/src/assets_audio_player.dart:78:27)
#4      Playlist.removeAtIndex.<anonymous closure> (package:assets_audio_player/src/playable.dart:442:20)
#5      SetBase.forEach (dart:collection/set.dart:143:30)
#6      Playlist.removeAtIndex (package:assets_audio_player/src/playable.dart:441:29)

so, maybe need check if indexList is empty, or any other better choice?

Audio? currentAudio() {
    if (indexList.isEmpty()) {
       return null;
    }
    return audioAt(at: indexList[playlistIndex]);
}