Pato05 / just_audio_media_kit

A platform interface for just_audio which wraps media_kit
https://pub.dev/packages/just_audio_media_kit
The Unlicense
8 stars 11 forks source link

Seeking before playback start not working consistently #6

Closed Chaphasilor closed 7 months ago

Chaphasilor commented 7 months ago

We have a feature where the last queue is restored when restarting our app. If the user already listened to X seconds of the current track, the player state will be restored to that position by first loading the queue (a ConcatenatingAudioSource), and then calling player.seek() to set the player to the correct position.

However, the position will reset to 0 before playback starts. I've had it work before when using debug builds (release build didn't work), but cannot reproduce that any longer. Currently it's resetting to 0 every time.
Similar behavior can also be observed with the just_audio_media_kit_example project, where seeking before playback starts will also be briefly reflected in the UI, but then playback will start at 0. This can be tested with the following modification:

try {
  // Preloading audio is not currently supported on Linux.
  await _player.setAudioSource(_playlist,
      preload: kIsWeb || defaultTargetPlatform != TargetPlatform.linux);
+ await _player.stop();
+ await _player.seek(const Duration(seconds: 45));
} catch (e) {
Pato05 commented 7 months ago

About this.. Yes, I had also noticed this while working on my media app, but I couldn't find any fixes for this (an attempt to do so can also be found in mediakit_player.dart:135.

Looking at this better, it seems that it is already implemented in upstream (media-kit/media-kit#581). I'll fix this soon.

EDIT: it seems that the latest version doesn't include this fix. For the time being, I guess the best way is to use the workaround described in https://github.com/media-kit/media-kit/issues/228#issuecomment-1803747439.

Chaphasilor commented 7 months ago

Interesting. I'll try this out tomorrow. Thanks for taking a look.
Hopefully the fix will be released soon, but the workaround would definitely be nice to have if it works. I'll report back!

Pato05 commented 7 months ago

@Chaphasilor Any news?

Chaphasilor commented 7 months ago

Haven't had time to look at it yet, busy with exams. But we're making progress with desktop support on all fronts, so I will definitely check this out in the coming days!

Pato05 commented 7 months ago

just_audio_media_kit v2.0.2 has been published which includes the fix (albeit temporary)

Chaphasilor commented 7 months ago

Okay, technically that was "in the coming days", but I'm still sorry it took me so long to take a look. Everything works fine with the update! Thanks a lot :)
Onto the remaining issues... ^^