restart method
重启播放器
Implementation
Future<void> restart() async {
if (_dispose) {
return;
}
if (value.videoPlayerController != null && value.videoPlayerController!.value.hasError) {
value.playerEventStreamController.sink
.add(BetterVideoPlayerEvent(value.playerKey, BetterVideoPlayerEventType.onRestart));
// remove error
value.videoPlayerController!.value = VideoPlayerValue(
duration: value.videoPlayerController!.value.duration,
size: value.videoPlayerController!.value.size,
position: value.videoPlayerController!.value.position,
caption: value.videoPlayerController!.value.caption,
buffered: value.videoPlayerController!.value.buffered,
isPlaying: value.videoPlayerController!.value.isPlaying,
isLooping: value.videoPlayerController!.value.isLooping,
isBuffering: value.videoPlayerController!.value.isBuffering,
volume: value.videoPlayerController!.value.volume,
playbackSpeed: value.videoPlayerController!.value.playbackSpeed,
errorDescription: null,
);
// auto play
value = value.copyWith(configuration: value.configuration.copyWith(autoPlay: true));
try {
await value.videoPlayerController!.initialize();
} catch (e) {
value.videoPlayerController!.value =
value.videoPlayerController!.value.copyWith(errorDescription: e.toString());
}
if (value.videoPlayerController!.value.hasError) {
return;
}
start();
}
}