I'm building a Flutter video player app and encountering the following error when trying to play videos:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(VideoError, Video player had error
com.google.android.exoplayer2.ExoPlaybackException:
Source error, null, null)
Code (Minimal Reproducible Example):
class VideoInfo extends StatefulWidget {
// ... other code ...
class _VideoInfoState extends State<VideoInfo> {
late VideoPlayerController _controller;
@override
Widget build(BuildContext context) {
return Scaffold(
body:
// ... other code ...
Widget _playView(BuildContext context){
final controller =_controller;
if(controller!=null&&controller.value.isInitialized){
return Container(
height: 300,
width: 300,
child: VideoPlayer(controller),
);
}else{
return Text("Being initialized pls wait");
}
}
_onTapVideo(int index){
final controller = VideoPlayerController.network(videoInfo[index]["videoUrl"]);
_controller= controller;
setState(() {
});
What I've tried:
video_player
dependency is included.android.permission.INTERNET
to the Android manifest.You are assigning a value of the same variable.
Use,
_controller = controller;
instead of,
_controller=_controller;