How can I make vide...
 
Share:
Notifications
Clear all

[Solved] How can I make video go full screen on webview android?

  

0
Topic starter

I can't display videos in full screen mode using webview app. I tried some solutions found on google but the issue still the same, in my case I can't see the full screen button when running videos in my website in WebView. I already tried some codes. anyone here who solved this problem.

android:hardwareAccelerated="true"
1 Answer
1

In your websettings add this.

myWebView.setWebChromeClient(new MyWebClient());

Now create class in same Activity.

private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.irmone.com")) {
//Content urls open in app
return false;

} else {
//Open external links in external browser or apps
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}

public class MyWebClient extends WebChromeClient
{
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;

public MyWebClient() {}

public Bitmap getDefaultVideoPoster()
{
if (MainActivity.this == null) {
return null;
}
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573);
}

public void onHideCustomView()
{
((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
MainActivity.this.setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}

public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = MainActivity.this.getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = MainActivity.this.getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)MainActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(3846);
}
}

Remember using this code you can enable video full screen but this will not works for ifram embedded videos.

 

Thanks you save my time.. I tried the code and it works perfectly.