setDataSource method
Future<void>
setDataSource(
- DataSource dataSource, {
- bool autoplay = true,
- bool looping = false,
- Duration seekTo = Duration.zero,
set the video data source
autoPlay
if this is true the video automatically start
Implementation
Future<void> setDataSource(
DataSource dataSource, {
bool autoplay = true,
bool looping = false,
Duration seekTo = Duration.zero,
}) async {
try {
_autoPlay = autoplay;
_looping = looping;
dataStatus.status.value = DataStatus.loading;
// if we are playing a video
if (_videoPlayerController != null &&
_videoPlayerController!.state.playing) {
await pause(notify: false);
}
_videoPlayerController = await _createVideoController(dataSource);
// set the video duration
customDebugPrint("Duration is ${_videoPlayerController!.state.duration}");
_duration.value = _videoPlayerController!.state.duration;
/// notify that video was loaded
dataStatus.status.value = DataStatus.loaded;
await _initializePlayer(seekTo: seekTo);
// listen the video player events
if (!_listenersInitialized) {
startListeners();
}
} catch (e, s) {
customDebugPrint(e);
customDebugPrint(s);
// _errorText ??= _videoPlayerController!.value.errorDescription ?? "$e";
dataStatus.status.value = DataStatus.error;
}
}