mod: seekTo

This commit is contained in:
guozhigq
2024-03-19 23:33:32 +08:00
parent 3498507132
commit 12f2e743c6

View File

@ -395,7 +395,13 @@ class PlPlayerController {
} }
// 配置Player 音轨、字幕等等 // 配置Player 音轨、字幕等等
_videoPlayerController = await _createVideoController( _videoPlayerController = await _createVideoController(
dataSource, _looping, enableHA, width, height, seekTo); dataSource,
_looping,
enableHA,
width,
height,
seekTo,
);
// 获取视频时长 00:00 // 获取视频时长 00:00
_duration.value = duration ?? _videoPlayerController!.state.duration; _duration.value = duration ?? _videoPlayerController!.state.duration;
updateDurationSecond(); updateDurationSecond();
@ -406,7 +412,7 @@ class PlPlayerController {
if (!_listenersInitialized) { if (!_listenersInitialized) {
startListeners(); startListeners();
} }
await _initializePlayer(seekTo: seekTo, duration: _duration.value); await _initializePlayer(duration: _duration.value);
bool autoEnterFullcreen = bool autoEnterFullcreen =
setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false); setting.get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullcreen && _isFirstTime) { if (autoEnterFullcreen && _isFirstTime) {
@ -426,7 +432,7 @@ class PlPlayerController {
bool enableHA, bool enableHA,
double? width, double? width,
double? height, double? height,
Duration seekTo, Duration? seekTo,
) async { ) async {
// 每次配置时先移除监听 // 每次配置时先移除监听
removeListeners(); removeListeners();
@ -508,9 +514,12 @@ class PlPlayerController {
play: false, play: false,
); );
} }
await player.open( player.open(
Media(dataSource.videoSource!, Media(
httpHeaders: dataSource.httpHeaders, start: seekTo), dataSource.videoSource!,
httpHeaders: dataSource.httpHeaders,
start: seekTo ?? Duration.zero,
),
play: false, play: false,
); );
// 音轨 // 音轨
@ -523,7 +532,6 @@ class PlPlayerController {
// 开始播放 // 开始播放
Future _initializePlayer({ Future _initializePlayer({
Duration seekTo = Duration.zero,
Duration? duration, Duration? duration,
}) async { }) async {
getVideoFit(); getVideoFit();
@ -551,6 +559,15 @@ class PlPlayerController {
await setPlaybackSpeed(1.0); await setPlaybackSpeed(1.0);
} }
} }
getVideoFit();
// if (_looping) {
// await setLooping(_looping);
// }
// 自动播放
if (_autoPlay) {
await play(duration: duration);
}
} }
List<StreamSubscription> subscriptions = []; List<StreamSubscription> subscriptions = [];