initVideo method
Implementation
Future<void> initVideo() async {
if (widget.src.trim().isEmpty) return;
try {
final gingacc = widget.document?.gingacc ?? GingaCC();
final parsedUri = gingacc.resolveUri(widget.src);
final VideoPlayerController controller;
if (kIsWeb || (parsedUri.hasScheme && parsedUri.scheme != 'file')) {
controller = VideoPlayerController.networkUrl(parsedUri);
} else if (parsedUri.isScheme('file')) {
controller = VideoPlayerController.file(File(parsedUri.toFilePath()));
} else {
controller = VideoPlayerController.file(
File(Uri.decodeComponent(parsedUri.path)));
}
_controller = controller;
if (notifyCompletion) {
controller.addListener(_onVideoPositionChanged);
}
await controller.initialize();
if (isLooping) {
await controller.setLooping(true);
}
await controller.setVolume(soundLevel);
if (mounted) {
setState(() {
_initialized = true;
});
}
if (isPlaying && !_isPaused) {
try {
await controller.play();
} catch (playErr) {
debugPrint("AVWidget play error: $playErr");
}
}
} catch (e) {
debugPrint("AVWidget Error initializing video: $e");
}
}