Merge branch 'fix'

This commit is contained in:
guozhigq
2024-04-16 23:48:10 +08:00

View File

@ -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(
@ -522,7 +522,22 @@ class PlPlayerController {
Duration seekTo = Duration.zero, Duration seekTo = Duration.zero,
Duration? duration, Duration? duration,
}) async { }) async {
// 设置倍速 getVideoFit();
// if (_looping) {
// await setLooping(_looping);
// }
/// 跳转播放
if (seekTo != Duration.zero) {
await this.seekTo(seekTo);
}
/// 自动播放
if (_autoPlay) {
await play(duration: duration);
}
/// 设置倍速
if (videoType.value == 'live') { if (videoType.value == 'live') {
await setPlaybackSpeed(1.0); await setPlaybackSpeed(1.0);
} else { } else {
@ -532,20 +547,6 @@ class PlPlayerController {
await setPlaybackSpeed(1.0); await setPlaybackSpeed(1.0);
} }
} }
getVideoFit();
// if (_looping) {
// await setLooping(_looping);
// }
// 跳转播放
if (seekTo != Duration.zero) {
await this.seekTo(seekTo);
}
// 自动播放
if (_autoPlay) {
await play(duration: duration);
}
} }
List<StreamSubscription> subscriptions = []; List<StreamSubscription> subscriptions = [];
@ -603,7 +604,9 @@ class PlPlayerController {
makeHeartBeat(event.inSeconds); makeHeartBeat(event.inSeconds);
}), }),
videoPlayerController!.stream.duration.listen((event) { videoPlayerController!.stream.duration.listen((event) {
if (event > Duration.zero) {
duration.value = event; duration.value = event;
}
}), }),
videoPlayerController!.stream.buffer.listen((event) { videoPlayerController!.stream.buffer.listen((event) {
_buffered.value = event; _buffered.value = event;
@ -646,6 +649,7 @@ class PlPlayerController {
/// 跳转至指定位置 /// 跳转至指定位置
Future<void> seekTo(Duration position, {type = 'seek'}) async { Future<void> seekTo(Duration position, {type = 'seek'}) async {
try {
if (position < Duration.zero) { if (position < Duration.zero) {
position = Duration.zero; position = Duration.zero;
} }
@ -654,14 +658,20 @@ class PlPlayerController {
_heartDuration = position.inSeconds; _heartDuration = position.inSeconds;
if (duration.value.inSeconds != 0) { if (duration.value.inSeconds != 0) {
if (type != 'slider') { if (type != 'slider') {
/// 拖动进度条调节时,不等待第一帧,防止抖动
await _videoPlayerController?.stream.buffer.first; await _videoPlayerController?.stream.buffer.first;
} }
await _videoPlayerController?.seek(position); await _videoPlayerController?.seek(position);
} else { } else {
_timerForSeek?.cancel(); _timerForSeek?.cancel();
_timerForSeek ??= _timerForSeek ??= _startSeekTimer(position);
Timer.periodic(const Duration(milliseconds: 200), (Timer t) async { }
} 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) { if (duration.value.inSeconds != 0) {
await _videoPlayerController!.stream.buffer.first; await _videoPlayerController!.stream.buffer.first;
await _videoPlayerController?.seek(position); await _videoPlayerController?.seek(position);
@ -670,7 +680,6 @@ class PlPlayerController {
} }
}); });
} }
}
/// 设置倍速 /// 设置倍速
Future<void> setPlaybackSpeed(double speed) async { Future<void> setPlaybackSpeed(double speed) async {
@ -708,11 +717,10 @@ class PlPlayerController {
await seekTo(Duration.zero); await seekTo(Duration.zero);
} }
await _videoPlayerController?.play(); await _videoPlayerController?.play();
playerStatus.status.value = PlayerStatus.playing;
await getCurrentVolume(); await getCurrentVolume();
await getCurrentBrightness(); await getCurrentBrightness();
playerStatus.status.value = PlayerStatus.playing;
// screenManager.setOverlays(false); // screenManager.setOverlays(false);
/// 临时fix _duration.value丢失 /// 临时fix _duration.value丢失