How to remove Youtube branding after embedding video in flutter

162 views Asked by At

I want to play a YouTube video in my Flutter app with the ability to hide EVERYTHING (Channel name, Video Title, and YouTube logo).

  • I initially attempted using the youtube_player_flutter package, but it proved incapable of achieving this.

  • Subsequently, I tried the youtube_player_iframe package, which claims to be 100% customizable. However, I couldn't find a way to hide everything. If you have any insights, please let me know.

enter image description here

I've made an attempt to achieve this. With my current approach, I've successfully hidden the YouTube logo and details from the video. However, I'm facing an issue with autoplay functionality not working. Any suggestions on how to resolve this would be appreciated.

If it's possible to achieve this using the youtube_player_iframe package, please provide guidance on how to implement it.

class YoutubePlayerWidget extends StatefulWidget {
  final String videoId;

  const YoutubePlayerWidget({Key? key, required this.videoId})
      : super(key: key);

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

class _YoutubePlayerWidgetState extends State<YoutubePlayerWidget> {
  late WebViewController _controller;

  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery.of(context).size.width;
    double screenHeight = screenWidth * (16 / 9);

    String youtubePlayerHtml =
        '''
      <html>
        <head>
          <style>
            body {
              margin: 0;
              overflow: hidden;
            }
            iframe {
              width: 100%;
              height: 100%;
              position: absolute;
              top: 0;
              left: 0;
            }
          </style>
        </head>
        <body>
          <iframe
            width="$screenWidth"
            height="$screenHeight"
            src="https://www.youtube.com/embed/${widget.videoId}?controls=0&modestbranding=1&rel=0&autoplay=1&showinfo=0"
            frameborder="0"
            allowfullscreen
            id="youtubeIframe"
          ></iframe>
        </body>
      </html>
    ''';

    return SizedBox(
      height: screenHeight,
      width: screenWidth,
      child: WebView(
        initialUrl: 'about:blank',
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _controller = webViewController;
          _controller.loadUrl(
              Uri.dataFromString(youtubePlayerHtml, mimeType: 'text/html')
                  .toString());
        },
      ),
    );
  }
}
0

There are 0 answers