fix: seekTo循环

This commit is contained in:
orz12
2024-03-13 21:22:41 +08:00
parent ff4ea8c457
commit e1343965b2

View File

@@ -102,7 +102,7 @@ class PlPlayerController {
final RxInt _vttSubtitlesIndex = 0.obs; final RxInt _vttSubtitlesIndex = 0.obs;
Timer? _timer; Timer? _timer;
StreamSubscription<Duration>? _bufferedListenerForSeek; Timer? _timerForSeek;
Timer? _timerForVolume; Timer? _timerForVolume;
Timer? _timerForShowingVolume; Timer? _timerForShowingVolume;
Timer? _timerForGettingVolume; Timer? _timerForGettingVolume;
@@ -551,8 +551,8 @@ class PlPlayerController {
} }
Future<void> autoEnterFullscreen() async { Future<void> autoEnterFullscreen() async {
bool autoEnterFullscreen = GStrorage.setting bool autoEnterFullscreen =
.get(SettingBoxKey.enableAutoEnter, defaultValue: false); GStrorage.setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullscreen) { if (autoEnterFullscreen) {
Future.delayed(const Duration(milliseconds: 500), () { Future.delayed(const Duration(milliseconds: 500), () {
if (dataStatus.status.value != DataStatus.loaded) { if (dataStatus.status.value != DataStatus.loaded) {
@@ -672,20 +672,31 @@ class PlPlayerController {
_position.value = position; _position.value = position;
updatePositionSecond(); updatePositionSecond();
_heartDuration = position.inSeconds; _heartDuration = position.inSeconds;
if (buffered.value == Duration.zero) { if (duration.value.inSeconds != 0) {
_bufferedListenerForSeek?.cancel();
_bufferedListenerForSeek = buffered.listen((status) {
if (status.inSeconds != 0) {
_bufferedListenerForSeek?.cancel();
_videoPlayerController?.seek(position);
}
});
} else {
if (type != 'slider') { if (type != 'slider') {
/// 拖动进度条调节时,不等待第一帧,防止抖动 /// 拖动进度条调节时,不等待第一帧,防止抖动
await _videoPlayerController?.stream.buffer.first; await _videoPlayerController?.stream.buffer.first;
} }
await _videoPlayerController?.seek(position); await _videoPlayerController?.seek(position);
// if (playerStatus.stopped) {
// play();
// }
} else {
print('seek duration else');
_timerForSeek?.cancel();
_timerForSeek =
Timer.periodic(const Duration(milliseconds: 200), (Timer t) async {
//_timerForSeek = null;
if (duration.value.inSeconds != 0) {
await _videoPlayerController?.stream.buffer.first;
await _videoPlayerController?.seek(position);
// if (playerStatus.status.value == PlayerStatus.paused) {
// play();
// }
t.cancel();
_timerForSeek = null;
}
});
} }
} }
@@ -1058,7 +1069,7 @@ class PlPlayerController {
_timerForVolume?.cancel(); _timerForVolume?.cancel();
_timerForGettingVolume?.cancel(); _timerForGettingVolume?.cancel();
timerForTrackingMouse?.cancel(); timerForTrackingMouse?.cancel();
_bufferedListenerForSeek?.cancel(); _timerForSeek?.cancel();
} }
// 记录播放记录 // 记录播放记录
@@ -1117,7 +1128,7 @@ class PlPlayerController {
_timerForVolume?.cancel(); _timerForVolume?.cancel();
_timerForGettingVolume?.cancel(); _timerForGettingVolume?.cancel();
timerForTrackingMouse?.cancel(); timerForTrackingMouse?.cancel();
_bufferedListenerForSeek?.cancel(); _timerForSeek?.cancel();
// _position.close(); // _position.close();
_playerEventSubs?.cancel(); _playerEventSubs?.cancel();
// _sliderPosition.close(); // _sliderPosition.close();