0

I am using flutter video player and chewie packages. My code works on android but not on ios, it gives an error like below, how can I solve it?

PlatformException (PlatformException(VideoError, Failed to load video: Cannot Open, null, null))

class _VideoViewState extends State<VideoView> {
  VideoPlayerController? videoPlayerController;
  ChewieController? chewieController;

  @override
  void initState() {
    super.initState();
    _initPlayer();
    log(widget.videoUrl, name: 'Url');
  }

  @override
  void dispose() {
    super.dispose();
    videoPlayerController?.dispose();
    chewieController?.dispose();
  }

  void _initPlayer() async {
    videoPlayerController = VideoPlayerController.network(widget.videoUrl);
    await videoPlayerController?.initialize();
    // setState(() {});
    chewieController = ChewieController(
      showOptions: true,
      showControls: true,
      allowPlaybackSpeedChanging: true,
      playbackSpeeds: [0.50, 0.75, 1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 2.00],
      videoPlayerController: videoPlayerController!,
      autoPlay: true,
      looping: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        centerTitle: true,
        title: Text(widget.title),
      ),
      body: chewieController != null
          ? Chewie(controller: chewieController!)
          : Center(
              child: Lottie.asset('assets/lotties/loading2.json'),
            ),
    );
  }
}

1 Answers1

0

There are a few things that could be causing this issue. First, make sure that you have the latest version of the video_player and chewie packages installed. If you are using an older version, try upgrading to see if that fixes the problem.

Another possibility is that the video_player package does not support the format of the video you are trying to play. Try converting the video to a different format and see if that works.

Finally, make sure that you have the correct permissions set up for iOS. In your Info.plist file, you will need to add the following keys:

NSPhotoLibraryUsageDescription - This is used if you want to allow the user to select a video from their photo library NSCameraUsageDescription - This is used if you want to allow the user to record a video NSMicrophoneUsageDescription - This is used if you want to allow the user to record audio with the video

Mohamed Elgazar
  • 778
  • 4
  • 9