Some one may mark as a duplicate issue.. Before mark it as duplicate please read my question fully. I have facing this problem last two days. I have tried all the answer that i got from the stackoverflow and even cloned some projects from github. But no answer is working for me and most important part is that same code work for me few days back. All the answers I have got are long days back. Please help me if you can.. Below my code
webView.setWebViewClient(new AppWebViewClients());
webView.setWebChromeClient(new MyWebClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}
try {
webView.loadUrl("https://www.youtube.com/watch?v=hlvbDjksdCg");
} catch (Exception e) {
Log.d(TAG, "run: " + e.getMessage());
}
MyWebClient
public class MyWebClient
extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
MyWebClient() {
}
public Bitmap getDefaultVideoPoster() {
if (StreamActivity.this == null) {
return null;
}
return BitmapFactory.decodeResource(StreamActivity.this.getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView() {
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(0);
StreamActivity.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 = StreamActivity.this.getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = StreamActivity.this.getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}
And lastly webview client
public class AppWebViewClients extends WebViewClient {
AppWebViewClients() {
pd=Util.createProgressDialog(StreamActivity.this);
pd.show();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pd.dismiss();
}
}