Search code examples
flutterdartandroid-video-playerflutterwave

VideoPlayerController.network() ran into source error


Im trying to play a video from the internet using VideoPlayerController.network() method but every single url that i try face with an error which is specified below :

Source error.
E/flutter ( 4250): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4, null)
E/flutter ( 4250): #0      ChewieController._initialize (package:chewie/src/chewie_player.dart:291:7)
E/flutter ( 4250): <asynchronous suspension>
E/flutter ( 4250): #1      new ChewieController (package:chewie/src/chewie_player.dart:197:5)
E/flutter ( 4250): #2      _ChewieListState.initState (package:flutterappvideoandshit/screens/chewie_list.dart:20:25)
E/flutter ( 4250): #3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4640:58)
E/flutter ( 4250): #4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #5      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #6      Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #7      SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #8      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #9      Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #10     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #14     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #15     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #16     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #17     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #20     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #21     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #22     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #23     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #24     Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #25     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #26     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter ( 4250): #27     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #28     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #29     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11)
E/flutter ( 4250): #30     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #31     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #33     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #34     Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #35     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #36     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #37     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #38     Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #39     SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1147:36)
E/flutter ( 4250): #40     SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1132:20)
E/flutter ( 4250): #41     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)

and here is my code :


import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
    home: HomePage(),
    );
  }
}
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Video Player"),
      ),
      body: ListView(
        children: <Widget>[
          ChewieList(
            videoPlayerController: VideoPlayerController.asset('assets/videos/soccer.mp4'),
            looping: true,
          ),
          ChewieList(
            videoPlayerController: VideoPlayerController.network(
                'https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
          ),
          /*
          ChewieList(
            videoPlayerController: VideoPlayerController.network(
                'http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
          )
           */
        ],
      ),
    );
  }
}




class ChewieList extends StatefulWidget {
  ChewieList({@required this.videoPlayerController,this.looping,Key key,}) : super(key:key);
  final VideoPlayerController videoPlayerController;
  final bool looping;

  @override
  _ChewieListState createState() => _ChewieListState();
}

class _ChewieListState extends State<ChewieList> {
  ChewieController _chewieController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _chewieController = ChewieController(
        videoPlayerController: widget.videoPlayerController,
        aspectRatio: 16/9,
        autoInitialize: true,
        looping: widget.looping,
        errorBuilder: (context,errMsg){
          return Center(
            child:Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(Icons.warning,color: Colors.yellowAccent,),
                Text("!خطایی در برقراری ارتباط رخ داده است",style: TextStyle(color: Colors.white),)
              ],
            ),
          );
        }
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    widget.videoPlayerController.dispose();
    _chewieController.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(8.0),
      child: Chewie(
        controller: _chewieController,
      ),
    );
  }
}


it's driving me crazy!!!! guys please help me .


Solution

  • You are using the wrong url. The url you posted is not the real video url but is only a redirect url.

    Try with:

    VideoPlayerController.network('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),

    (Remember that iOS simulators and other does not always support video playing.)