0

Problem: my youtube videoplayer is not working even though I've put in the youtube video ID and controller. I would like some suggestions on how to fix this error.

I'm trying to create a widget that can take the youtube video ID and return a video player that plays a video off of youtube.

Unfortunately I can't use the normal VideoPlayer widget (I've tried using the you-link.herokuapp.com API and it doesn't return the links) and the Youtube player doesn't seem to work - it just displays a loading screen.

I would like this to work for web so downgrading the package isn't an option.

Currently I've tried using the embed link (youtube.com/embed/(videoID)) but I find that this doesn't work for some of the videos I want to embed (I get a "watch on youtube" error).

Is there either a) a resource that converts the youtube video link (which I can obtain from the ID) to a link that can be embedded in the Flutter VideoPlayer b) or is there something that I haven't done with the Youtube Player that will make it work?

code: (I've done all imports, not including them here)

class _VideoPopupState extends State<VideoPopup> {
  YoutubePlayerController _controller;
  bool _isPlayerReady;

  @override
  void initState(){
    super.initState();
    _isPlayerReady = false;
    _controller = YoutubePlayerController(

      initialVideoId: widget.vidID,

      flags: YoutubePlayerFlags(
        autoPlay: false,
        mute: false,
      ),
    );
    }


  void dispose(){
    super.dispose();
    _controller.dispose();

  }
  void listener() {
    if(_isPlayerReady && mounted && !_controller.value.isFullScreen){
//
    }
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),//tells user what to expect
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [

            Expanded(
              child: YoutubePlayer(
                showVideoProgressIndicator: true,
                onReady: (){
                  print('lets go');
                  _isPlayerReady = true;
                },

                controller: _controller,
                liveUIColor: Colors.amber,

              ),
            ),



           ],

        ),
        
      ),
    );
  }
}

pubspec:

  cupertino_icons: ^1.0.2
  http: ^0.13.3
  video_player: ^2.1.12
  youtube_player_flutter: ^8.0.0

No errors coming up, so I'm really confused to why it isn't working.

gdxgrace
  • 33
  • 4

0 Answers0