Repository: bluefireteam/audioplayers

Issue #843: Error after playing music several times with AudioCache
Created: 2021-04-10T08:48:09Z
Error after playing music several times with AudioCache.
Full Description
By executing the following code, an error occurs when press the button several times.
I found that there are already related issues:
#773 #682 #766
I think the reason of the issue is at play method of AudioCache.
Future<AudioPlayer> play(
    String fileName, {
    double volume = 1.0,
    bool? isNotification,
    PlayerMode mode = PlayerMode.MEDIA_PLAYER,
    bool stayAwake = false,
    bool recordingActive = false,
    bool? duckAudio,
  }) async {
    String url = await getAbsoluteUrl(fileName);
    AudioPlayer player = _player(mode);
    player.setReleaseMode(ReleaseMode.STOP); // this line
    await player.play(
      url,
      volume: volume,
      respectSilence: isNotification ?? respectSilence,
      stayAwake: stayAwake,
      recordingActive: recordingActive,
      duckAudio: duckAudio ?? this.duckAudio,
    );
    return player;
  }

This line was added because #618 . That is a good PR, but it will cause errors when not using fixedPlayer. Maybe due to large amount of AudioPlayer will not be released.
I think we should add a judgment like this:
Future<AudioPlayer> play(
    String fileName, {
    double volume = 1.0,
    bool? isNotification,
    PlayerMode mode = PlayerMode.MEDIA_PLAYER,
    bool stayAwake = false,
    bool recordingActive = false,
    bool? duckAudio,
  }) async {
    String url = await getAbsoluteUrl(fileName);
    AudioPlayer player = _player(mode);
    
    // this three lines
    if (fixedPlayer != null) {
      player.setReleaseMode(ReleaseMode.STOP);
    }
    
    await player.play(
      url,
      volume: volume,
      respectSilence: isNotification ?? respectSilence,
      stayAwake: stayAwake,
      recordingActive: recordingActive,
      duckAudio: duckAudio ?? this.duckAudio,
    );
    return player;
  }

If my idea meets the needs, I'm interested in working on a PR for this.
Code to Reproduce
// Create a reference
final AudioCache _audioCache = AudioCache(prefix: 'assets/audio/');

// Press several times, an error occurs
TextButton(
  onPressed: () {
    _audioCache.play('demo.mp3');
  },
  child: Text('Play'),
),

Log Errors
D/MediaPlayer( 5024): setSubtitleAnchor in MediaPlayer
E/MediaPlayer( 5024): error (1, -19)
E/MediaPlayer( 5024): Error (1,-19)
E/MediaPlayer( 5024): pause called in state 0, mPlayer(0x83798720)
E/MediaPlayer( 5024): error (-38, 0)
E/MediaPlayer( 5024): Attempt to perform seekTo in wrong state: mPlayer=0x83798720, mCurrentState=0
E/MediaPlayer( 5024): error (-38, 0)
E/MediaPlayer( 5024): Error (-38,0)
E/MediaPlayer( 5024): Error (-38,0)

Files/URLs/Sources
None.
Screenshots
None.
Platforms

OS: Android
OS version: 7.1.2
Device: physical device. Internal model.
flutter version: 2.0.3
audioplayers version: 0.18.3
release or not release: release and debug modes.
does the error occur and does it have any peculiarities: No.

Duplicate issue #862: Audio Cache Not working in android
Created: 2021-04-30T17:07:05Z
For first few clicks on instance of audio cache it plays sound, but later on it starts to throw error

Closing comment (2021-05-05T07:27:31Z): Is it the same as #843 ?