Issue
I have been looking for a solution to this for weeks while keep putting it on my backlog.
I have a simple webview as following
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);
I am passing iFrame to it, the video loads and plays ok but the fullscreen option is not available.
Solutions I tried
Enable JavaScript
Set WebChromeClient
LoadDataWithBaseURL with
https://
I also have allowfullscreen
for example the following iframe
<iframe width="560" height="315" src="https://www.youtube.com/embed/somevideoID" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
Any solution to this?
Solution
To enable the full screen button on the YouTube player, the WebChromeClient
has to implement OnShowCustomView
and OnHideCustomView
and thus it it your responsibility to define what is "full screen" for your app as it does not have to be defined by the device's screen size.
Note: You still need the HTML5 tag of allowfullscreen
in your iFrame html source
So lets assume you have this type of layout:
LinearLayout (id = linearLayout)
LinearLayout (id = contentLayout)
Button
WebView
You can subclass WebChromeClient
and define how you wish to display "full screen" content, in this example we will assume the most outer LinearLayout
is where we want to display the YouTube video, the inner LinearLayout
contains all the Activity's content that you wish to hide while the full screen video is playing.
WebChromeClient Implementation:
public class FullScreenClient : WebChromeClient
{
readonly FrameLayout.LayoutParams matchParentLayout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
ViewGroup.LayoutParams.MatchParent);
readonly ViewGroup content;
readonly ViewGroup parent;
View customView;
public FullScreenClient(ViewGroup parent, ViewGroup content)
{
this.parent = parent;
this.content = content;
}
public override void OnShowCustomView(View view, ICustomViewCallback callback)
{
customView = view;
view.LayoutParameters = matchParentLayout;
parent.AddView(view);
content.Visibility = ViewStates.Gone;
}
public override void OnHideCustomView()
{
content.Visibility = ViewStates.Visible;
parent.RemoveView(customView);
customView = null;
}
}
SetWebChromeClient Implementation:
webView.SetWebChromeClient(new FullScreenClient(linearLayout, contentLayout));
Answered By - SushiHangover
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.