Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Fullscreen is not pure full screen feature. #278

Open
princeteck opened this issue Jun 30, 2020 · 8 comments
Open

[BUG] Fullscreen is not pure full screen feature. #278

princeteck opened this issue Jun 30, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@princeteck
Copy link

Everything works fine for me, just the fullscreen thing. its just rotating the orientation of the app. If I go back from the full screen, the app orientation is landscape which is not expected. also all the widgets are not hidden like appbar and other widget when we go full screen.

_controller.value.isFullScreen is a final value so I am not even able to use it to show or hide the widgets based on the full screen state.

Screenshot 2020-06-30 at 5 06 05 PM

@princeteck princeteck added the bug Something isn't working label Jun 30, 2020
@GitDoGui
Copy link

GitDoGui commented Jul 1, 2020

Hi @princeteck. I had a similar issue and I managed to solve it by adding a boolean variable to know when we are or not using Fullscreen, so I can change AppBar to null when we are using Fullscreen. Also, I added a WillPopScope widget to handle the back button press when Fullscreen to exit fullscreen. Here is my final file. I receive a Live Object as Parameter.

class LiveDetail extends StatefulWidget {
  final Live live;

  LiveDetail({
    Key key,
    @required this.live,
  }) : super(key: key);

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

class _LiveDetailState extends State<LiveDetail> {
  YoutubePlayerController _controller;

  bool showAppBar = true;

  @override
  void initState() {
    _controller = YoutubePlayerController(
      initialVideoId: widget.live.videoId,
      flags: YoutubePlayerFlags(autoPlay: true, isLive: widget.live.isLive, controlsVisibleAtStart: true),
    );
    super.initState();
  }

  Future<bool> _onWillPop() {
    if (_controller.value.isFullScreen) {
      _controller.toggleFullScreenMode();
    } else {
      Navigator.pop(context);
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onWillPop,
      child: MaterialApp(
        title: 'Live',
        theme: ThemeData(primaryColor: Color(CustomColors.grena)),
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: showAppBar
                ? AppBar(
                    title: Text(widget.live.title),
                    leading: new IconButton(
                      icon: new Icon(Icons.arrow_back),
                      onPressed: () {
                        Navigator.pop(context);
                      },
                    ),
                  )
                : null,
            body: Container(
              child: YoutubePlayerBuilder(
                player: YoutubePlayer(controller: _controller),
                builder: (context, player) {
                  return Column(
                    children: <Widget>[player],
                  );
                },
                onEnterFullScreen: () {
                  setState(() {
                    showAppBar = false;
                  });
                },
                onExitFullScreen: () {
                  setState(() {
                    showAppBar = true;
                  });
                },
              ),
            )),
      ),
    );
  }
}

@sarbagyastha
Copy link
Owner

Simply place your Scaffold under YoutubePlayerBuilder

@princeteck
Copy link
Author

Simply place your Scaffold under YoutubePlayerBuilder

this seems to work but now one new issue I am facing. the video is cropped when tested on live device but shows correctly on iOS simulator. I think the aspect Ratio is screwed up.

@Luktm
Copy link

Luktm commented Aug 17, 2020

Hi @princeteck. I had a similar issue and I managed to solve it by adding a boolean variable to know when we are or not using Fullscreen, so I can change AppBar to null when we are using Fullscreen. Also, I added a WillPopScope widget to handle the back button press when Fullscreen to exit fullscreen. Here is my final file. I receive a Live Object as Parameter.

class LiveDetail extends StatefulWidget {
  final Live live;

  LiveDetail({
    Key key,
    @required this.live,
  }) : super(key: key);

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

class _LiveDetailState extends State<LiveDetail> {
  YoutubePlayerController _controller;

  bool showAppBar = true;

  @override
  void initState() {
    _controller = YoutubePlayerController(
      initialVideoId: widget.live.videoId,
      flags: YoutubePlayerFlags(autoPlay: true, isLive: widget.live.isLive, controlsVisibleAtStart: true),
    );
    super.initState();
  }

  Future<bool> _onWillPop() {
    if (_controller.value.isFullScreen) {
      _controller.toggleFullScreenMode();
    } else {
      Navigator.pop(context);
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onWillPop,
      child: MaterialApp(
        title: 'Live',
        theme: ThemeData(primaryColor: Color(CustomColors.grena)),
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: showAppBar
                ? AppBar(
                    title: Text(widget.live.title),
                    leading: new IconButton(
                      icon: new Icon(Icons.arrow_back),
                      onPressed: () {
                        Navigator.pop(context);
                      },
                    ),
                  )
                : null,
            body: Container(
              child: YoutubePlayerBuilder(
                player: YoutubePlayer(controller: _controller),
                builder: (context, player) {
                  return Column(
                    children: <Widget>[player],
                  );
                },
                onEnterFullScreen: () {
                  setState(() {
                    showAppBar = false;
                  });
                },
                onExitFullScreen: () {
                  setState(() {
                    showAppBar = true;
                  });
                },
              ),
            )),
      ),
    );
  }
}

But setstate will rebuild the widget, mean the video will restart again and again when onEnterFullScreen and onExitFullScreen callback triggered

@Akiat
Copy link

Akiat commented Jan 16, 2021

Simply place your Scaffold under YoutubePlayerBuilder

I'm sorry to re-open this issue, but I used this workaround and I got the same result as @princeteck. The video is cropped, so I can't see all the captions.

If someone have a solution for this it would be great :)

@nileshrathore
Copy link

The problem is occurring because this plugin scaling player in the case of fullscreen. I was able to solve this problem by removing the manual scaling.

Steps to solve this problem:-

  1. Copy the below files of the plugin to your project (so we can change the plugin code).
    Screenshot 2021-03-01 at 5 49 45 PM

  2. Now go to copied youtube_player.dart and navigate to buildPlayer() method, and remove the Transform.scale widget(parent widget of RawYoutubePlayer) from hierarchy and use RawYoutubePlayer directly. This will solve your problem because we do not want to scale the video. Please look at the attached screenshot for a better context of how your buildPlayer() method looks before and after.
    Screenshot 2021-03-01 at 6 15 31 PM

@biel-correa
Copy link

Hi @princeteck. I had a similar issue and I managed to solve it by adding a boolean variable to know when we are or not using Fullscreen, so I can change AppBar to null when we are using Fullscreen. Also, I added a WillPopScope widget to handle the back button press when Fullscreen to exit fullscreen. Here is my final file. I receive a Live Object as Parameter.

class LiveDetail extends StatefulWidget {
  final Live live;

  LiveDetail({
    Key key,
    @required this.live,
  }) : super(key: key);

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

class _LiveDetailState extends State<LiveDetail> {
  YoutubePlayerController _controller;

  bool showAppBar = true;

  @override
  void initState() {
    _controller = YoutubePlayerController(
      initialVideoId: widget.live.videoId,
      flags: YoutubePlayerFlags(autoPlay: true, isLive: widget.live.isLive, controlsVisibleAtStart: true),
    );
    super.initState();
  }

  Future<bool> _onWillPop() {
    if (_controller.value.isFullScreen) {
      _controller.toggleFullScreenMode();
    } else {
      Navigator.pop(context);
    }
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onWillPop,
      child: MaterialApp(
        title: 'Live',
        theme: ThemeData(primaryColor: Color(CustomColors.grena)),
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: showAppBar
                ? AppBar(
                    title: Text(widget.live.title),
                    leading: new IconButton(
                      icon: new Icon(Icons.arrow_back),
                      onPressed: () {
                        Navigator.pop(context);
                      },
                    ),
                  )
                : null,
            body: Container(
              child: YoutubePlayerBuilder(
                player: YoutubePlayer(controller: _controller),
                builder: (context, player) {
                  return Column(
                    children: <Widget>[player],
                  );
                },
                onEnterFullScreen: () {
                  setState(() {
                    showAppBar = false;
                  });
                },
                onExitFullScreen: () {
                  setState(() {
                    showAppBar = true;
                  });
                },
              ),
            )),
      ),
    );
  }
}

Or you can only change the toolbarHeight param in the AppBar

56 is the deffault value

AppBar(
        title: Text('Your title'),
        toolbarHeight: _fullScreen ? 0 : 56,
),

@muyiwah
Copy link

muyiwah commented Dec 19, 2023

The problem is occurring because this plugin scaling player in the case of fullscreen. I was able to solve this problem by removing the manual scaling.

Steps to solve this problem:-

  1. Copy the below files of the plugin to your project (so we can change the plugin code).
    Screenshot 2021-03-01 at 5 49 45 PM
  2. Now go to copied youtube_player.dart and navigate to buildPlayer() method, and remove the Transform.scale widget(parent widget of RawYoutubePlayer) from hierarchy and use RawYoutubePlayer directly. This will solve your problem because we do not want to scale the video. Please look at the attached screenshot for a better context of how your buildPlayer() method looks before and after.
    Screenshot 2021-03-01 at 6 15 31 PM

This worked, was almost dropping the pluggin until i followed the instruction, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants