start method

Future<void> start()

开始播放

Implementation

Future<void> start() async {
  if (_dispose) {
    return;
  }

  // 检查错误
  if (videoPlayerValue?.hasError == true) {
    return;
  }

  // 开始自动播放
  if (value.configuration.autoPlay && value.visibilityFraction > 0) {
    play();
  }

  // 设置播放循环
  await value.videoPlayerController?.setLooping(value.configuration.looping);

  // 监听网络连接,如果 wifi 断开,提醒用户
  _connectivitySubscription?.cancel();
  var connectivityResult = await Connectivity().checkConnectivity();
  if (connectivityResult == ConnectivityResult.wifi) {
    _connectivitySubscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
      if (value.videoPlayerController?.hasListeners == true) {
        if (result != ConnectivityResult.wifi) {
          value = value.copyWith(wifiInterrupted: true);
          if (videoPlayerValue?.isPlaying ?? false) {
            pause();
          }
        }
      }
    });
  }
}