fix: seekTo异常
This commit is contained in:
@ -473,17 +473,17 @@ class PlPlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 字幕
|
// 字幕
|
||||||
if (dataSource.subFiles != '' && dataSource.subFiles != null) {
|
// if (dataSource.subFiles != '' && dataSource.subFiles != null) {
|
||||||
await pp.setProperty(
|
// await pp.setProperty(
|
||||||
'sub-files',
|
// 'sub-files',
|
||||||
UniversalPlatform.isWindows
|
// UniversalPlatform.isWindows
|
||||||
? dataSource.subFiles!.replaceAll(';', '\\;')
|
// ? dataSource.subFiles!.replaceAll(';', '\\;')
|
||||||
: dataSource.subFiles!.replaceAll(':', '\\:'),
|
// : dataSource.subFiles!.replaceAll(':', '\\:'),
|
||||||
);
|
// );
|
||||||
await pp.setProperty("subs-with-matching-audio", "no");
|
// await pp.setProperty("subs-with-matching-audio", "no");
|
||||||
await pp.setProperty("sub-forced-only", "yes");
|
// await pp.setProperty("sub-forced-only", "yes");
|
||||||
await pp.setProperty("blend-subtitles", "video");
|
// await pp.setProperty("blend-subtitles", "video");
|
||||||
}
|
// }
|
||||||
|
|
||||||
_videoController = _videoController ??
|
_videoController = _videoController ??
|
||||||
VideoController(
|
VideoController(
|
||||||
@ -603,7 +603,9 @@ class PlPlayerController {
|
|||||||
makeHeartBeat(event.inSeconds);
|
makeHeartBeat(event.inSeconds);
|
||||||
}),
|
}),
|
||||||
videoPlayerController!.stream.duration.listen((event) {
|
videoPlayerController!.stream.duration.listen((event) {
|
||||||
duration.value = event;
|
if (event > Duration.zero) {
|
||||||
|
duration.value = event;
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
videoPlayerController!.stream.buffer.listen((event) {
|
videoPlayerController!.stream.buffer.listen((event) {
|
||||||
_buffered.value = event;
|
_buffered.value = event;
|
||||||
@ -646,32 +648,38 @@ class PlPlayerController {
|
|||||||
|
|
||||||
/// 跳转至指定位置
|
/// 跳转至指定位置
|
||||||
Future<void> seekTo(Duration position, {type = 'seek'}) async {
|
Future<void> seekTo(Duration position, {type = 'seek'}) async {
|
||||||
if (position < Duration.zero) {
|
try {
|
||||||
position = Duration.zero;
|
if (position < Duration.zero) {
|
||||||
}
|
position = Duration.zero;
|
||||||
_position.value = position;
|
|
||||||
updatePositionSecond();
|
|
||||||
_heartDuration = position.inSeconds;
|
|
||||||
if (duration.value.inSeconds != 0) {
|
|
||||||
if (type != 'slider') {
|
|
||||||
/// 拖动进度条调节时,不等待第一帧,防止抖动
|
|
||||||
await _videoPlayerController?.stream.buffer.first;
|
|
||||||
}
|
}
|
||||||
await _videoPlayerController?.seek(position);
|
_position.value = position;
|
||||||
} else {
|
updatePositionSecond();
|
||||||
_timerForSeek?.cancel();
|
_heartDuration = position.inSeconds;
|
||||||
_timerForSeek ??=
|
if (duration.value.inSeconds != 0) {
|
||||||
Timer.periodic(const Duration(milliseconds: 200), (Timer t) async {
|
if (type != 'slider') {
|
||||||
if (duration.value.inSeconds != 0) {
|
await _videoPlayerController?.stream.buffer.first;
|
||||||
await _videoPlayerController!.stream.buffer.first;
|
|
||||||
await _videoPlayerController?.seek(position);
|
|
||||||
t.cancel();
|
|
||||||
_timerForSeek = null;
|
|
||||||
}
|
}
|
||||||
});
|
await _videoPlayerController?.seek(position);
|
||||||
|
} else {
|
||||||
|
_timerForSeek?.cancel();
|
||||||
|
_timerForSeek ??= _startSeekTimer(position);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
print('Error while seeking: $err');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer? _startSeekTimer(Duration position) {
|
||||||
|
return Timer.periodic(const Duration(milliseconds: 200), (Timer t) async {
|
||||||
|
if (duration.value.inSeconds != 0) {
|
||||||
|
await _videoPlayerController!.stream.buffer.first;
|
||||||
|
await _videoPlayerController?.seek(position);
|
||||||
|
t.cancel();
|
||||||
|
_timerForSeek = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// 设置倍速
|
/// 设置倍速
|
||||||
Future<void> setPlaybackSpeed(double speed) async {
|
Future<void> setPlaybackSpeed(double speed) async {
|
||||||
/// TODO _duration.value丢失
|
/// TODO _duration.value丢失
|
||||||
|
|||||||
Reference in New Issue
Block a user