createVideoPlayerController method
创建播放器
Implementation
Future<void> createVideoPlayerController({required BetterVideoPlayerDataSource dataSource}) async {
late VideoPlayerController videoPlayerController;
switch (dataSource.type) {
case BetterVideoPlayerDataSourceType.network:
videoPlayerController = VideoPlayerController.network(dataSource.url);
break;
case BetterVideoPlayerDataSourceType.file:
videoPlayerController = VideoPlayerController.file(File(dataSource.url));
break;
case BetterVideoPlayerDataSourceType.asset:
videoPlayerController = VideoPlayerController.asset(dataSource.url);
break;
}
try {
// 创建后必须要初始化才能使用
await videoPlayerController.initialize();
} catch (e) {
print(e);
videoPlayerController.value = videoPlayerController.value.copyWith(errorDescription: e.toString());
}
// 绑定播放控制器
attachVideoPlayerController(videoPlayerController: videoPlayerController);
_isCreateVideoPlayerController = true;
}