ryanheise / just_audio

Audio Player
1.04k stars 667 forks source link

calling seek on the player restarts the audio from the beginning #553

Closed Haidar0096 closed 3 years ago

Haidar0096 commented 3 years ago

Which API doesn't behave as documented, and how does it misbehave? It is method seek of AudioPlayer

Minimal reproduction project NOTE: PLease don't close this again, I can give the link to the repo if you want but I already provided you with the necessary code in my opinion to understand the problem, just tell me if you need more info to know

I can't provide a custom minimal reproducible code right now bcz the code base is very large but here are a fragment that can explain the problem very well

in my service class:

print('seekEvent Arrived with duration = $position, player position before is ${_player.position}');
      await _player.seek(position); // _players is the AudioPlayer inside my service class
      print('seekEvent Ended , player position after is ${_player.position}');
      print('seekEvent and total duration is ${_player.duration}');
      print('seekEvent and _positionSubject value is ${_positionSubject.value}');

my bloc event handler:

 FutureOr<PlayerBlocState> _handleSeekToPositionEvent(
          _SeekToPosition event) async =>
      (await _playerService.seekToPosition(event.position))
          .fold(_errorState, (_) => state);

my seekbar: (it just adds an event to the bloc, and it is present inside a stream builder (more about the stream below)

slider = Slider(
                  value: value,
                  min: min,
                  max: max,
                  onChanged: (value) {
                    print('min is $min and max is $max and value is $value');
                    playerBloc.add(
                      PlayerBlocEvent.seekToPosition(
                        Duration(
                          milliseconds: value.round(),
                        ),
                      ),
                    );
                  },
                );

in the init method of my service class I have a stream that listens to the positionStream of the AudioPlayer and emits the same events (this duplication is because I am using an interface and not the AudioPlayer directly in my code, just clean architecture):


 subscription = _player.positionStream.listen(
          (duration) => _positionSubject.add(duration),
          onDone: () => subscription.cancel(),
        );

here are the logs of the above print statements, you can see that the AudioPlayer and my own stream are all updating their values correctly, But when I am listening to the sound being played, it is actually being restarted from the beginning:

I/flutter (17488): seekEvent Arrived with duration = 0:00:19.365000, player position before is 0:00:02.480447
//at this point I call seek 
I/flutter (17488): seekEvent Ended , player position after is 0:00:19.411578
I/flutter (17488): seekEvent and total duration is 0:00:23.178000
I/flutter (17488): seekEvent and _positionSubject value is 0:00:19.408982

I am testing this on a real android phone with android version 8.0.0 Huawei p10 lite

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Error messages

If applicable, copy & paste error message here, within the triple quotes to preserve formatting.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

insert output of "flutter doctor" here

Additional context Add any other context about the problem here.

Haidar0096 commented 3 years ago

I just found that this issue is a dupplicate of #333 I will close it here and follow that issue

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.