bboy
bboy

Reputation: 41

Can't use fullscreen on YoutubeVideoPlayer Flutter (happen on android native devices)

Can use fullscreen video player when develop on android emulator, but on android native device its only go fullscreen but in portrait orientation. (Didn't set preferred orientation in main.dart)

I'm currently using this package https://pub.dev/packages/youtube_player_flutter

Image on Android Native Device



  @override
  Widget build(BuildContext context) {
    final argumentsData =
        ModalRoute.of(context).settings.arguments as List<String>;
    final youtubeUrl = argumentsData[0];
    final title = argumentsData[1];
    String youtubeId = YoutubePlayer.convertUrlToId(youtubeUrl);

    YoutubePlayerController _controller = YoutubePlayerController(
      initialVideoId: youtubeId,
    );
    return OrientationBuilder(
      builder: (context, orientation) {
        if (orientation == Orientation.landscape) {
          return Scaffold(
            body: youtubePlayer(_controller),
          );
        } else {
          return Scaffold(
            appBar: BackAppBar(),
            body: Column(
              children: [
                kSizedBoxVerticalXS,
                Text(
                  title,
                  style: Theme.of(context).textTheme.headline3,
                ),
                kSizedBoxVerticalXS,
                youtubePlayer(_controller),
              ],
            ),
          );
        }
      },
    );
  }

  Widget youtubePlayer(YoutubePlayerController controller) {
    return YoutubePlayerBuilder(
      player: YoutubePlayer(
        controller: controller,
        aspectRatio: 16 / 9,
      ),
      builder: (context, player) {
        return Column(
          children: [
            player,
          ],
        );
      },
    );
  }

Upvotes: 1

Views: 3940

Answers (1)

bboy
bboy

Reputation: 41

Use this package https://pub.dev/packages/youtube_player_iframe instead an old ones

This is reason from Maker : https://github.com/sarbagyastha/youtube_player_flutter/issues/289

Upvotes: 3

Related Questions