sarbagyastha / youtube_player_flutter

A Flutter plugin for inline playback or streaming of YouTube videos using the official iFrame Player API.
https://youtube.sarbagyastha.com.np
BSD 3-Clause "New" or "Revised" License
695 stars 795 forks source link

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

Open princeteck opened 4 years ago

princeteck commented 4 years ago

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

GitDoGui commented 4 years ago

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 commented 4 years ago

Simply place your Scaffold under YoutubePlayerBuilder

princeteck commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 9 months ago

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