I am working in paint project were, I need to display the list of videos, which works fine. But when the video is playing it is showing something codec does not support config priority (err -2147483648)
in console,
Here I am using ImagePicker
to record video from the camera and passing to VideoPlayerController
.
class VideoScaling extends StatefulWidget {
@override
_VideoScalingState createState() => new _VideoScalingState();
}
class _VideoScalingState extends State<VideoScaling> {
VideoPlayerController videoController;
bool _isPlaying = false;
var _videoPath;
String _videoP;
VoidCallback videoPlayerListener;
List<VideoPlayerController> _listOfVideos = [];
void _video() async {
_videoPath =
await ImagePicker.pickVideo(source: ImageSource.camera).then((p) {
_videoP = p.path;
});
_startVideoPlayer();
}
VideoPlayerController vcontroller;
Future<void> _startVideoPlayer() async {
// print('path video: ${_videoP}');
vcontroller = new VideoPlayerController.file(new File(_videoP));
videoPlayerListener = () {
if (videoController != null && videoController.value.size != null) {
// Refreshing the state to update video player with the correct ratio.
if (mounted) setState(() {});
videoController.removeListener(videoPlayerListener);
}
};
vcontroller.addListener(videoPlayerListener);
await vcontroller.setLooping(true);
await vcontroller.initialize();
await videoController?.dispose();
if (mounted) {
setState(() {
videoController = vcontroller;
_listOfVideos.add(videoController);
});
}
await vcontroller.play();
}
void _pause() async {
await vcontroller.play();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: new Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
videoController != null
? Column(
children: _listOfVideos
.map((p) => InkWell(
onTap: () {},
child: Padding(
padding: EdgeInsets.all(10.0),
child: Container(
height: 200.0,
width: 200.0,
child: VideoPlayer(p)),
),
))
.toList(growable: false),
)
: Container(
color: Colors.red,
),
_recordVideo(context),
],
),
),
);
}
Widget _recordVideo(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
onPressed: () {
_startVideoPlayer();
},
icon: Icon(Icons.play_arrow),
),
IconButton(
onPressed: () {
setState(() {
videoController = null;
});
_video();
},
icon: Icon(Icons.add_circle),
),
IconButton(
onPressed: () {
_pause();
},
icon: Icon(Icons.stop),
),
],
);
}
}
Add '/' correctly in video paths
Then :
Tools->Flutter->Flutter Clean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With