【问题标题】:Xamarin Forms (PCL) Youtube Player loading in a WebViewXamarin Forms (PCL) Youtube Player 在 WebView 中加载
【发布时间】:2021-09-29 21:04:19
【问题描述】:

我们有想要在 Xamarin Forms (PCL) 项目上运行的 YouTube 预告片。

我们已经尝试了一切,但不知何故那里没有一个好的 Youtube 播放器:(

所以现在我们在 WebView 中加载 Youtube 预告片,以便它在 Android + iOS 上运行。

这是我们在 WebView 组件中加载预告片的方式:

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; 

但不知何故,预告片在 iOS 和 Android 上运行,但自动播放不起作用,相关电影仍然出现!

所以我的问题是:

  1. 有没有办法在 Xamarin Forms 平台上设置自动播放?
  2. 为什么自动播放功能不起作用?

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.android xamarin.ios youtube


    【解决方案1】:

    大多数移动平台(Android、iOS)上的自动播放被阻止以避免糟糕的用户体验 - 视频只能在用户操作后播放。 与 Andriod 一样,自 Android SDK 17 起禁用自动播放。 您可以查看此问题以获取更多信息Android webview html5 video autoplay not working on android 4.0.3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 2018-08-11
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2020-10-01
      相关资源
      最近更新 更多