setupDataSource method
Setup new data source in Better Player.
Implementation
Future setupDataSource(BetterPlayerDataSource betterPlayerDataSource) async {
postEvent(BetterPlayerEvent(BetterPlayerEventType.setupDataSource,
parameters: <String, dynamic>{
_dataSourceParameter: betterPlayerDataSource,
}));
_postControllerEvent(BetterPlayerControllerEvent.setupDataSource);
_hasCurrentDataSourceStarted = false;
_hasCurrentDataSourceInitialized = false;
_betterPlayerDataSource = betterPlayerDataSource;
_betterPlayerSubtitlesSourceList.clear();
///Build videoPlayerController if null
if (videoPlayerController == null) {
videoPlayerController = VideoPlayerController(
bufferingConfiguration:
betterPlayerDataSource.bufferingConfiguration);
videoPlayerController?.addListener(_onVideoPlayerChanged);
}
///Clear asms tracks
betterPlayerAsmsTracks.clear();
///Setup subtitles
final List<BetterPlayerSubtitlesSource>? betterPlayerSubtitlesSourceList =
betterPlayerDataSource.subtitles;
if (betterPlayerSubtitlesSourceList != null) {
_betterPlayerSubtitlesSourceList
.addAll(betterPlayerDataSource.subtitles!);
}
if (_isDataSourceAsms(betterPlayerDataSource)) {
_setupAsmsDataSource(betterPlayerDataSource).then((dynamic value) {
_setupSubtitles();
});
} else {
_setupSubtitles();
}
///Process data source
await _setupDataSource(betterPlayerDataSource);
setTrack(BetterPlayerAsmsTrack.defaultTrack());
}