Flutter: YouTube player change the orientation of screen ,How can we open video in YouTube app? Edited#2

Viewed 2877

I have an app show YouTube video ,when i click on the right-bottom square to full screen mode ,it is be full screen with rotate the screen orientation ,then when i click back button to exit full screen it still horizontal and when i rotate the device it don't correct the orientation I am using this :

YoutubePlayerController _controller = YoutubePlayerController(
        initialVideoId: 'xxxxxx?controls=0',
        flags: YoutubePlayerFlags(
          autoPlay: false,
          mute: false,
        ));

Show the video

YoutubePlayer(
                        controller: _controller,
                        showVideoProgressIndicator: true,
                        progressIndicatorColor: Colors.blueAccent,
                      )),

How can we open video in YouTube app?

2 Answers

Override your dispose method as following:

@override
  void dispose() {
    _controller.dispose();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    super.dispose();
  }

WillPopScope will help to rotate the screen to portrait mode when the back button is pressed.

_controller.toggleFullScreenMode() internally toggles landscape to portrait and vise versa as called.

body: WillPopScope(
        onWillPop: () async {
          _controller.toggleFullScreenMode();
          return Future.value(false);
        },
        child: YoutubePlayer(
            controller: _controller,
            ...
            ...
           )
Related