Home > Software engineering >  Flutter Youtube Player Auto Fullscreen
Flutter Youtube Player Auto Fullscreen

Time:12-17

I am using "youtube_player_flutter: ^8.1.1" plugin for play to youtube videos. I want it to be full screen automatically when the video starts.

late YoutubePlayerController _controller;

  @override
  void initState() {
    _controller = YoutubePlayerController(
        initialVideoId: 'zgOdG2lQQAC',
        flags: const YoutubePlayerFlags(autoPlay: false, loop: false));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return YoutubePlayerBuilder(
      player: YoutubePlayer(controller: _controller),
      builder: (context, player) {
        return Scaffold(
          appBar: const AppBarWidget(appBarTitle: solutionVideos),
          body: Padding(
            padding: EdgeInsets.symmetric(
                horizontal: context.dynamicWidth(20),
                vertical: context.dynamicWidth(20)),
            child: Column(
              children: [
                SizedBox(
                    width: context.dynamicWidth(2.2),
                    height: context.dynamicHeight(6),
                    child: player)
              ],
            ),
          ),
        );
      },
    );
  }

CodePudding user response:

late YoutubePlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = YoutubePlayerController(
      initialVideoId: 'yNrmluocNFw',
      flags: const YoutubePlayerFlags(
        autoPlay: false,
        loop: false,
      ),
    );
    _controller.toggleFullScreenMode();
  }

You can use the _controller to toggle it to full screen. Try the above code,it worked for me.

  • Related