flutterdartflutter-video-playeryoutube-player-flutter

Flutter: YouTube video keeps loading


I'm using youtube_player_flutter package to play YouTube videos by link, the video is playing but the loading Circular progress indicator keep showing despite the video is playing and loaded.

Here's a gif of the result:

enter image description here

Here's the code:

class YouTubeVideoWidget extends StatefulWidget {
  final String url;

  const YouTubeVideoWidget({super.key, required this.url});

  @override
  State<YouTubeVideoWidget> createState() => _YouTubeVideoWidgetState();
}

class _YouTubeVideoWidgetState extends State<YouTubeVideoWidget> {
  
  late YoutubePlayerController controller;
  
  @override
  void initState(){
    super.initState();
    String? videoId = YoutubePlayer.convertUrlToId(widget.url,)!;

    controller = YoutubePlayerController(
      initialVideoId: videoId,
      flags: YoutubePlayerFlags(
        autoPlay: true,
        hideThumbnail: true,
        
      )
    );
    
  }
  @override
  Widget build(BuildContext context) {
    return YoutubePlayer(
      controller: controller,
      progressColors: ProgressBarColors(
        backgroundColor: Colors.grey.shade300,
        playedColor: Colors.orange,
      ),
      progressIndicatorColor: Colors.orange,
      onReady: (){},
    );
  }
  }

What i have missed!


Solution

  • Use this version:

    youtube_player_flutter: ^8.1.2