Closed gkovac42 closed 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.
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.
it's work fine using single instance of AudioPlayer
@yiky84119 thanks for info.
@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.
@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:
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.
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.