initializeVideoPlayerController method
Future<void>
initializeVideoPlayerController(
)
Implementation
Future<void> initializeVideoPlayerController() async {
isInitializing = true;
isLocallyAvailable = true;
onLoading(true);
final String? url = await widget.asset.getMediaUrl();
if (url == null) {
onError(true);
if (mounted) {
setState(() {});
}
onLoading(false);
return;
}
final Uri uri = Uri.parse(url);
if (Platform.isAndroid) {
videoController = VideoPlayerController.contentUri(uri);
} else {
videoController = VideoPlayerController.networkUrl(uri);
}
try {
await videoController?.initialize();
hasLoaded = true;
videoController?.setLooping(widget.isLoop);
if (widget.isAutoPlay) {
videoController?.play();
}
} catch (e, s) {
FlutterError.presentError(
FlutterErrorDetails(
exception: e,
stack: s,
library: 'insta_assets_picker',
silent: true,
),
);
onError(true);
} finally {
if (mounted) {
setState(() {});
}
}
onLoading(false);
}