1

I am trying to put a network video from a different site in Flutter.

I have used the video_player package. I have used a future builder in which, the CircularProgressIndicator will keep running until the video is loaded. When i run the app, in the start the CircularProgressIndicator keep on running and after a few seconds it stops as if the video is loaded but it show complete blankness on the emulator. In other words the video is not loading.

After i start the app

enter image description here

After Loading

enter image description here

This is the code

class MyHomePage extends StatefulWidget {
  @override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;

  @override
  void initState() {
    _controller = VideoPlayerController.network(
        'https://ok.ru/videoembed/1616636152346');
    _initializeVideoPlayerFuture = _controller.initialize();
    _controller.setLooping(true);
    _controller.setVolume(1.0);
    super.initState();
  }


  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
      ),
      body: FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot){
          if(snapshot.connectionState == ConnectionState.done){
            return AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: VideoPlayer(_controller),
            );
          } else {
            return Center(
              child: CircularProgressIndicator(backgroundColor: Colors.blue,
              ),
            );
          }
        }
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          setState(() {
            if(_controller.value.isPlaying){
              _controller.pause();
            }else{
              _controller.play();
            }
          });
        },
        child: Icon(_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
      ),
    ),
    );
  }
}
Amin Zaidi
  • 23
  • 1
  • 6
  • Your link is for a web page not a video file. Make sure you use a link to an MP4 video file to get a working result. Example: http://techslides.com/demos/sample-videos/small.mp4 – VC.One Sep 11 '20 at 20:09

1 Answers1

0

Your link for video is not a valid video link , it is a embed Url.

To Play a video from network URL use direct video URL like https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4.

Put this link in your videoController , it will working fine.