0

I have divided screens into multiple zones and in of them each trying to play multiple videos. The problem is the app crashes after playing videos for few seconds.
Here is the playing logic. I think the issue lies here somewhere.

 @override
  void initState() {
    super.initState();
    _initController();
  }



void _initController() {
    _controller = VideoPlayerController.file(File(mediaItems[currentIndex].filePath ??""))
      ..initialize().then((_)  {
        setState(() {});
        _controller.setVolume(0.0);
        _controller.play();
        setState(() {});

      });
    _controller.addListener(() {

      if (_controller.value.isCompleted ?? false) {
        if(toogle) {   //isCompleted is being called at the start of a video too, so to skipit.
          currentIndex = (currentIndex + 1) % mediaItems.length;
          _onControllerChange(mediaItems[currentIndex].filePath ?? "");
        }
        toogle = !toogle;
      }
    });
  }

  Future<void> _onControllerChange(String link) async {
    if (_controller == null) {
      // If there was no controller, just create a new one
      _initController();
    } else {
      // If there was a controller, we need to dispose of the old one first
     // await _controller.pause();
      final oldController = _controller;

      // Registering a callback for the end of next frame
      // to dispose of an old controller
      // (which won't be used anymore after calling setState)


      WidgetsBinding.instance.addPostFrameCallback((_)  async {
        oldController.removeListener(() { });
          oldController.dispose();

        // Initing new controller

      });
      _initController();

      // Making sure that controller is not used by setting it to null
// setState(() {
      //   _controller = null;
      // });
    }
  }
 @override
  Widget build(BuildContext context) {
return  VideoPlayer(_controller);
}

I tried using different packages for video_player like video_player_win. I tried adding a custom video player having different decoders but didn't work. I tried checking performance overlay but performance is normal until suddenly Jank occurs and app crashes. Using windows task manager I check the memory usage which was not much on avg 250 mbps.

3
  • Is there any specific error message you're encountering? Commented Jan 11, 2024 at 11:13
  • Only " Lost connection to device". After much testing and research I have found issue to be deallocation and allocation of memory to video controllers. Commented Jan 12, 2024 at 14:56
  • @Ahmedijaz Did you manage to fix this ? I am experiencing the same issue. Just a hard crash. No logs being caught. And only on my release version of the app. On debug it works fine, no error in logs. But in release. Hard crashes the app. No logs being caught by my app crash logger (Sentry) Commented Jan 23 at 17:46

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.