Xamarin Forms (PCL) Youtube Player loading in a WebView

Ekrem 1 Reputation point
2021-07-22T15:16:51.903+00:00

We have YouTube trailers that we want to run on our Xamarin Forms (PCL) project.

We have try'd everything but somehow there is not a good Youtube player out there :(

So now we are loading the Youtube trailers in a WebView so that it runs on the Android + iOS.

This is how we load the trailers in our WebView component:

But somehow the Trailer is running on iOS and Android but the Autoplay is not working and the related movies still show up!

We have YouTube trailers that we want to run on our Xamarin Forms (PCL) project.

We have try'd everything but somehow there is not a good Youtube player out there :(

So now we are loading the Youtube trailers in a WebView so that it runs on the Android + iOS.

This is how we load the trailers in our WebView component:

var apiRequest = "https://www.youtube.com/embed/GYmm9qNwd_s?html5=1&autoplay=1&loop=1&rel=0&showinfo=0&controls=1";

var webView = new WebView();
webView.Source = apiRequest;
webView.MinimumWidthRequest = 200;
webView.MinimumHeightRequest = 200;
webView.HorizontalOptions = LayoutOptions.FillAndExpand;
webView.VerticalOptions = LayoutOptions.FillAndExpand;

var stackLayout = new StackLayout();

stackLayout.Children.Add(webView);

stackLayout.HorizontalOptions = LayoutOptions.FillAndExpand;
stackLayout.VerticalOptions = LayoutOptions.FillAndExpand;

grid.Children.Add(stackLayout);

this.Content = grid;

But somehow the Trailer is running on iOS and Android but the Autoplay is not working and the related movies still show up!

117181-screenshot.jpg
117191-screenshot2.jpg

So my question is :

  1. Is there a way to set the Autoplay on the Xamarin Forms platforms?
  2. Why does the autoplay function won't work?
Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2021-07-23T04:16:41.04+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    According to the Google official statement, functions and parameters such as autoplay, playVideo(), loadVideoById() won't work in all mobile environments. So it's unable to make the embed video display automatically in a webview. You could search with the keyword as YouTube Player API iframe Embeds to check the related doc.

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.