1

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.

2
  • I have the same problem with web here. The error is UnimplementedError: init() has not been implemented. It works on debug and local but not on release. I tried many things and some answers says to use html as web renderer on release however it seems web renderer is deprecated in my version of Flutter Commented Jan 28 at 18:30
  • @rickyxd I ended up switching to a different video plugin just for windows: pub.dev/packages/media_kit. There is an open issue here: github.com/jakky1/video_player_win/issues/23 . But well no solution. So far, mediakit works really well. I might just use it for all platforms instead of windows too. Commented Feb 15 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.