media-kit / media-kit

A cross-platform video player & audio player for Flutter & Dart.
https://github.com/media-kit/media-kit
MIT License
893 stars 126 forks source link

Seek is not working on release mode #804

Closed BTMuli closed 2 weeks ago

BTMuli commented 2 weeks ago

I use the code below:

await player.open(Playlist(hive.allMedia, index: hive.index), play: play);
var progress = hive.getProgress(index);
if (progress != 0) {
  debugPrint('跳转到上次播放进度: $progress');
  await player.seek(Duration(milliseconds: progress));
  // Here's a custom snackbar widget
  await Infobar(context, '已跳转到上次播放进度 $progress');
}

And it runs normally in debugMode and profileMode,but when I bundle my app in release,it show the snackbar but the video play from 0 instead of jump to the true position.

BTMuli commented 2 weeks ago

It is so strange that it works well in profile mode but got wrong under release.🤔

abdelaziz-mahdy commented 2 weeks ago

your problem is that video is not loaded before you seek check this for possible fixes https://github.com/media-kit/media-kit/issues/228

for me i use

await player.stream.buffer.first;

your code will be

await player.open(Playlist(hive.allMedia, index: hive.index), play: play);
await player.stream.buffer.first;
var progress = hive.getProgress(index);
if (progress != 0) {
  debugPrint('跳转到上次播放进度: $progress');
  await player.seek(Duration(milliseconds: progress));
  // Here's a custom snackbar widget
  await Infobar(context, '已跳转到上次播放进度 $progress');
}

for me it works correctly.

BTMuli commented 2 weeks ago

await player.stream.buffer.first;

Thanks,I'll try it,but why I could seek directly in profile mode?

abdelaziz-mahdy commented 2 weeks ago

i think because the video was cached? thats the only thing i could think of

BTMuli commented 2 weeks ago

Thanks!await player.stream.buffer.first; really works.