Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter-codec does not support config priority (err -2147483648) while playing video

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),
        ),
      ],
    );
  }
}
like image 468
satish Avatar asked Aug 04 '18 17:08

satish


1 Answers

Add '/' correctly in video paths

Then :

Tools->Flutter->Flutter Clean
like image 86
Tasnuva Tavasum oshin Avatar answered Sep 17 '22 13:09

Tasnuva Tavasum oshin