Flutter just_audio stopping/pausing functionality not working for my application

30 Views Asked by At

I am trying to develop a cross-platform application that plays audio for theatrical purposes and I can play the audio, but I cannot stop it. My code in my AudioPlayback (audio_playback.dart) object is below for stopping the AudioPlayer from just_audio:

 Future<void> stopAudio() async {
    debugPrint("Stopping audio playback");
    await player.stop();
  }

I am calling stop from a different widget than the main body widget, but I do not think that should be an issue.

Here is the link to my stop button code: https://github.com/bgoldstone/cue_go/blob/main/lib/cue_widgets/playback_bar.dart

The stop functionality starts on line 123 and this is a playback bar within the application.

application screenshot

I tried wrapping the stop in the cue_list.dart setState function and using async await and then

1

There are 1 best solutions below

2
Vladyslav Ulianytskyi On

It's looks like you mess something with callback

final void Function(void Function()) cueListState;

When you tap on IconButton and callback onPressed worked, in these lines:

 widget.cueListState(() {
                  if (cue.player.isPlaying()) {
                    cue.player.stopAudio();
                  }
                });

you just throw a function at the top with this code:

() {
     if (cue.player.isPlaying()) {
     cue.player.stopAudio();
    }
}

but you don't call this piece of code:

if (cue.player.isPlaying()) {
     cue.player.stopAudio();
    }

try this:

onPressed: () {
          for (Cue cue in widget.cues) {
            debugPrint(
                'Cue ${cue.name} ${cue.player.isPlaying()} Playing: ${cue.player.isPlaying()}');
****************
            if (cue.player.isPlaying()) {
                cue.player.stopAudio();
              }
***************
            debugPrint("stopped cue: ${cue.cueNumber}");
            debugPrint("Cue playing: ${cue.player.isPlaying()}");
          }
        },