start method
Implementation
Future<void> start() async {
if (_dispose) {
return;
}
// 检查错误
if (videoPlayerValue?.hasError == true) {
bool hasError = value.hasError;
value = value.copyWith(hasError: videoPlayerValue?.hasError ?? false);
if (hasError == false && value.hasError == true) {
value.playerEventStreamController.sink
.add(BetterVideoPlayerEvent(value.playerKey, BetterVideoPlayerEventType.onError));
}
return;
}
// 开始自动播放
if (value.configuration.autoPlay) {
if (value.visibilityFraction > 0) {
play();
}
}
await value.videoPlayerController?.setLooping(value.configuration.looping);
// 监听网络连接
_connectivitySubscription?.cancel();
var connectivityResult = await Connectivity().checkConnectivity();
if (connectivityResult == ConnectivityResult.wifi) {
_connectivitySubscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
if (result != ConnectivityResult.wifi) {
value = value.copyWith(wifiInterrupted: true);
if (videoPlayerValue?.isPlaying ?? false) {
pause();
}
}
});
}
}