0

Good afternoon, please help with the audio_service plugin, I don't understand how to make a slider that won't move when audio is loaded with a bad Internet connection

StreamBuilder _timeLineSlider(double playbackSlider) {
return StreamBuilder<MediaState>(
    stream: _mediaStateStream,
    builder: (context, snapshot) {
      final mediaState = snapshot.data;

      _playEnded(
        mediaState?.position.inSeconds ?? 0,
        mediaState?.mediaItem?.duration?.inSeconds ?? 0
      );

      Duration _duration = mediaState?.position ?? Duration.zero;

      return SeekBar(
        duration: mediaState?.mediaItem?.duration ?? Duration.zero,
        position: _duration.inSeconds > 0 ? _duration : Duration.zero,
        onChangeEnd: AudioService.seekTo
      );
    }
); }

That's how I did it, but if the connection is bad, the slider moves while the audio doesn't play

I get a position like this

Stream<MediaState> get _mediaStateStream =>
  Rx.combineLatest2<MediaItem?, Duration, MediaState>(
      AudioService.currentMediaItemStream,
      AudioService.positionStream,
          (mediaItem, position) => MediaState(mediaItem, position));
  • 1
    The issue must be with `AudioService.positionStream` which is incorrectly updating the position when it shouldn't be. But you didn't show the code that updates the position from your background audio task. Are you just forwarding position updates from just_audio directly? If so, then it is a bug with just_audio and you should report it there. – Ryan Heise Aug 28 '21 at 13:44
  • I use an audioplayers plugin, but the mechanism is similar to just_audio. So I just pass the position from the stream to the slider, otherwise I don't know how to do it – Stepan Bezhuk Aug 28 '21 at 14:22
  • 1
    You'll need to update your question with the information of how you're broadcasting the state from the background audio task. I.e. exactly what parameters you're passing into `setState` and when. – Ryan Heise Aug 29 '21 at 12:11
  • The problem was solved, you were right – Stepan Bezhuk Sep 07 '21 at 09:01

0 Answers0