So I suspect this will be a hard one. But here we go. I have my video player. I use the Chewie plugin. Coupled with the Video Player plugin. Now, my flutter code is used amongst 4 platforms. Android, iOS, macOS and windows. The video player works well in RELEASE mode for Android, iOS, macOS. However for windows. It does not work. It hard crashes the windows application when I try to initialize the VideoPlayerController. Crashes it so hard that the cause of the crash is not even picked up by my Sentry crash handler.
In debug mode. The video player on windows is initizaled without issues and plays the video fine. However in release it just crashes. I have no logs because flutter does not pick up logs in release mode and in debug no error or issues are thrown. Here below is my code:
@RoutePage()
class VideoPlayerPage extends ConsumerStatefulWidget {
const VideoPlayerPage({
super.key,
required this.file,
});
final File file;
@override
ConsumerState<ConsumerStatefulWidget> createState() =>
_VideoPlayerPageState();
}
class _VideoPlayerPageState extends ConsumerState<VideoPlayerPage> {
ChewieController? _chewieController;
VideoPlayerController? _videoController;
late Future<void> _videoFuture;
late final File file;
final _chewieProgressColors = ChewieProgressColors(
backgroundColor: ColorName.grey1,
bufferedColor: ColorName.grey3,
handleColor: ColorName.white,
playedColor: ColorName.grey7,
);
@override
void initState() {
super.initState();
file = widget.file;
_videoController = VideoPlayerController.networkUrl(Uri.file(file.path));
_videoFuture = _initializeChewieController();
}
@override
void dispose() {
_videoController?.dispose();
_chewieController?.dispose();
super.dispose();
}
Future<void> _initializeChewieController() async {
try {
if (_videoController != null) {
await _videoController!.initialize();
setState(() {
_chewieController = ChewieController(
videoPlayerController: _videoController!,
autoPlay: true,
autoInitialize: true,
aspectRatio: _videoController!.value.aspectRatio,
materialProgressColors: _chewieProgressColors,
cupertinoProgressColors: _chewieProgressColors,
showControlsOnInitialize: false,
zoomAndPan: true,
deviceOrientationsOnEnterFullScreen: [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
DeviceOrientation.portraitUp,
],
deviceOrientationsAfterFullScreen: [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
);
});
}
} catch (e) {
logger.e('Error at initializing video controller', error: e);
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return Scaffold(
appBar: MyAppBar(
hasBackButton: true,
title: l10n.videoPlayerText,
),
backgroundColor: ColorName.black,
body: SafeArea(
child: FutureBuilder(
future: _videoFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: MyAnimatedSpinner(),
);
}
if (_chewieController == null) {
return Center(
child: MyIcon(asset: Assets.lib.assets.icons.iconReport),
);
}
return Center(
child: Chewie(
controller: _chewieController!,
),
);
},
)),
);
}
}
The hard crash happens in the _initializeChewieController function at the line await _videoController!.initialize();.
So any ideas? I have been looking for reported issues. But cannot find nothing.