I am using Just-Audio to play asset files (for now, I will eventually move to stream them) but I have a requirement to fade audio in and out over a certain period of time. Now, there is a workaround in which I just load the files in that fade in and out, but the audio is between 10 and 30 minutes long, and one way I thought of reducing the file size was to try and have a gapless loop, and each loop reduce the volume, but I can't seem to get it working.
Here is an example of what I'm trying to do:
void fadeoutAudio() {
for (int i = 0; i < 10; i++) {
_audioPlayer.playerStateStream.listen((PlayerState state) {
switch (state.processingState) {
case ProcessingState.ready:
print(ProcessingState.ready);
_audioPlayer.play();
break;
case ProcessingState.completed:
print(ProcessingState.completed);
_volume = _volume - 0.1;
_audioPlayer.setVolume(_volume);
_audioPlayer.play();
break;
}
});
}
I call this in initstate. The audio plays once, and when printing the state I can see that I get to Completed, but it doesn't play again.
Any thoughts on a solution for this?