alexmercerind / flutter_audio_desktop

[WIP] An 🎵 audio playback library for Flutter Desktop. Supports Windows & Linux. Based on miniaudio.
MIT License
52 stars 18 forks source link

Using 2nd instance of AudioPlayer crashes the app #21

Closed gkovac42 closed 3 years ago

gkovac42 commented 3 years ago

Whenever I try to use 2 instances of AudioPlayer on the same screen it crashes the app without any errors in the logs. It happens both on 0.0.7 and 0.0.8 with distinct ids passed to AudioPlayer's constructors.

alexmercerind commented 3 years ago

13 is a potential duplicate.

MichealReed commented 3 years ago

Could you please provide more info? I have successfully used over 1,000 instances on the same screen. Are you trying to use load twice on the same instance as mentioned in the issue @alexmercerind referenced?

edit: a snippet from your code would help.

yiky84119 commented 3 years ago

same issue.

static void play() async { final audioPlayer = new AudioPlayer(id: 0); await audioPlayer.load('./assets/audio/warning.mp3'); await audioPlayer.play(); }

method play(), call twice or more, then crash.

yiky84119 commented 3 years ago

1

yiky84119 commented 3 years ago

it's work fine using single instance of AudioPlayer

alexmercerind commented 3 years ago

@yiky84119 thanks for info.

MichealReed commented 3 years ago

@yiky84119 please open a separate issue for this if it persists, you are not using two audio players in the code example you provided. It seems you are creating the object player, loading the media, and playing all in one method. You shouldn't do this and should keep play separate, with the object construction and load method in init or another method that is only called once.

gkovac42 commented 3 years ago

@MichealReed Sorry for the late reply. Here is my code:

AudioPlayer soundPlayer = AudioPlayer(id: 0);
AudioPlayer musicPlayer = AudioPlayer(id: 1);

void playSound(String sound) async {
  try {
    await soundPlayer.load(sound);
    await soundPlayer.play();
  } catch (e) {
    print(e);
  }
}

void playMusic(String music) async {
  try {
    await musicPlayer.load(music);
    await musicPlayer.play();
  } catch (e) {
    print(e);
  }
}

On 0.0.7 using just one instance of the player works just fine, but as soon as I try to use both on the same screen the app will crash. On 0.0.8 I get this error as soon as the app launches and then it crashes:

ss1

MichealReed commented 3 years ago

As with the other comment here, your play button is not only calling play, it also calls load. https://github.com/alexmercerind/flutter_audio_desktop/issues/13

Also, please be sure to use the "new" keyword when generating new instances.