Is there a way to check whether a VideoPlayerController from the Flutter video-player package is already disposed?
Use try-catch block
try{
_videoController.dispose();
//Do something
}
catch(e){
//Do something
}
Christian
I'm an Android programmer who studied bioinformatics at the Free University of Berlin. I wrote the proposal for https://biology.stackexchange.com/ and my current pet project is BetterEar. Small children can hear the difference between all kind of different phonemes but once they grow older they lose the ability to hear phoneme differences in foreign languages that their native language doesn't make. As a result most German native speakers can't hear the difference between belief and believe, between advice and advise or between effect and affect. My Android App trains the ability to hear the difference between different phonemes by giving the learner deliberate feedback. This allows the learner to regain the ability to distinguish phonemes that they lost as a child. While some people think that the way to improve information flow is through building brain-computer interfaces that can magically push information into brains, I think it makes sense to do our best to optimize the information flow of our existing channels. After school I went to study bioinformatics because I thought the way to improve the human brain is through looking at neurons. Today, I think improving the human brain is more about finding the right kind of stimulus. The human brain is an amazing learning machine on it's own and we don't need to put any electrodes into it, to train it to do better.
Updated on November 26, 2022Comments
-
Christian over 1 year
At a point in my code I now that I won't need a
VideoPlayerController
anymore but I'm not sure whether or not aVideoPlayerController
is already disposed. Currently, I call thedispose()
method but when theVideoPlayerController
is already disposed that throws the error:2021-04-08 23:35:07.602 1898-2090/com.learningleaflets.anatomyleaflet E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: A VideoPlayerController was used after being disposed. Once you have called dispose() on a VideoPlayerController, it can no longer be used. #0 ChangeNotifier._debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:117:9) #1 ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6) #2 ChangeNotifier.dispose (package:flutter/src/foundation/change_notifier.dart:212:12) #3 VideoPlayerController.dispose (package:video_player/video_player.dart:383:11) <asynchronous suspension>
I don't want that error to fill my logs, so is there a way to check whether a
VideoPlayerController
is already disposed to avoiding callingdispose()
on it?-
Huthaifa Muayyad about 3 yearsI don't think this is the cause of the error being displayed. The error means that you tried to use the
VideoPlayerController
after it was disposed. Could be done by mistake also if more than one video is using the same controller. You dispose of it in the first video, then try to use the same one to play the second video, then this error is thrown.
-
-
Christian about 3 yearsWhat should I do in the catch?
-
Sourav9063 about 3 yearsDepends on your use cases. If you use this, no error will fill your logs as required by your ques.
-
gautam singh almost 2 yearsits not catched in the dispose method ``` try { videoNotifier.videoPlayerController .removeListener(videoNotifier.listener); videoNotifier.videoPlayerController.dispose(); } catch (e) { log('Err : dispose custom controller $e'); } finally { super.dispose(); } ```