我一直在寻找一个解决这个问题的几个星期,同时不断把它放在我的积压。
我有一个简单的webview如下
WebView webView = FindViewById<WebView>(Resource.Id.webviewVideo);
webView.ClearCache(true);
webView.ClearHistory();
webView.SetWebChromeClient( new WebChromeClient { });
webView.Settings.JavaScriptEnabled = true;
webView.Settings.LoadWithOverviewMode = true;
webView.Settings.UseWideViewPort = true;
webView.LoadDataWithBaseURL("https://.", iFrameString, "text/html", "UTF-8", null);
字符串
我正在将iFrame传递给它,视频加载和播放正常,但全屏选项不可用。
我尝试的解决方案
- 启用JavaScript
- 设置WebChromeClient
- 使用
https://
的LoadDataWithBaseURL
我也有allowfullscreen
例如下面的iframe
<iframe width="560" height="315" src="https://www.youtube.com/embed/somevideoID" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
型
有什么解决办法吗?
3条答案
按热度按时间js4nwp541#
要在YouTube播放器上启用全屏按钮,
WebChromeClient
必须实现OnShowCustomView
和OnHideCustomView
,因此您有责任为您的应用定义什么是“全屏”,因为它不必由设备的屏幕大小定义。注意:您仍然需要在iFrame html源代码中使用
allowfullscreen
的HTML5标记假设你有这样的布局:
字符串
您可以子类化
WebChromeClient
并定义您希望如何显示“全屏”内容,在此示例中,我们将假设最外部的LinearLayout
是我们希望显示YouTube视频的位置,内部的LinearLayout
包含您希望在全屏视频播放时隐藏的所有Activity内容。WebChromeClient实现:
型
SetWebChromeClient实现:
型
3duebb1j2#
我知道答案已经被接受了,但我花了一些时间来完成所提供的代码。我从来没有见过“readonly”关键字,“override”不太应该在那里,看起来他回答了LinearLayout并提供了FrameLayout. LayoutParams。我希望这只是真的很好的psudocode笑。如果没有,请告诉我代码语法!
我在一个非常有用的YouTube video的评论部分发布了这个链接。如果你是从那里来的,你需要向VideoAdapter类构造函数添加2个参数。一个用于LinearLayout(parent),一个用于RecyclerView(content)。
感谢@SushiHangover提供代码。你会帮助很多人!别忘了对他的回答投赞成票。
我的父布局是LinearLayout**(父),子布局是RecyclerView(内容)**,可以容纳多个视频。
字符串
9q78igpj3#
webView.webChromeClient = object:public void run(){
字符串