I'm creating a music application using Flutter and I'm using the soundpool package. I'm wondering if there's another way to loop the soundtrack other than this:
while (true) {
soundStreamId = await pool.play(soundId);
print("Loopin");
if (status == false) {
break;
}
}
By using break, the sound does not stop immediately but it will stop after the track is played completely.
I've tried replacing break with pool.stop(soundStreamId) and pool.pause(soundStreamId) but it gives me this error:
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: 'package:soundpool/soundpool.dart': Failed assertion: line 189 pos 12: 'streamId > 0': Invalid 'streamId' parameter. Only values greater than 0 are valid.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 Soundpool.stop (package:soundpool/soundpool.dart:189:12)
#3 SoundServices.toggleSound (package:Waver/api/sound_service.dart:33:20)
<asynchronous suspension>
#4 _AutoSoundSetterState._toggleSpectrumAnalyzer (package:Waver/Widgets/Setup/AutoSoundSetter.dart:51:20)
#5 _AutoSoundSetterState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:Waver/Widgets/Setup/AutoSoundSetter.dart:211:31)
#6 State.setState (package:flutter/src/widgets/framework.dart:1244:30)
#7 _AutoSoundSetterState.build.<anonymous closure>.<anonymous closure> (package:Waver/Widgets/Setup/AutoSoundSetter.dart:203:27)
Please advise. Thanks!
question from:https://stackoverflow.com/questions/65560249/is-there-a-way-to-loop-a-soundpool-sound-track-flutter-package