I am trying to implement a subclass of WebChromeClient in order to have a working full-screen button on youtube embedded videos (for example: https://www.youtube.com/embed/dQw4w9WgXcQ ) inside a WebView.
I basically simplified this repo , here are some snippets:
VideoWebChromeClient:
public class VideoWebChromeClient extends WebChromeClient { private boolean isVideoFullscreen = false; private View activityNonVideoView; private ViewGroup activityVideoView; private View videoViewContainer; private CustomViewCallback videoCallback; private Window videoWindow; public VideoWebChromeClient(View activityNonVideoView, ViewGroup activityVideoView, Window window) { this.activityNonVideoView = activityNonVideoView; this.activityVideoView = activityVideoView; this.videoWindow = window; } @Override public void onShowCustomView(View view, CustomViewCallback callback) { Log.w("ENTER FULLSCREEN"); videoCallback = callback; videoViewContainer = view; videoWindow.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); activityNonVideoView.setVisibility(View.GONE); activityVideoView.addView(videoViewContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); activityVideoView.setVisibility(View.VISIBLE); isVideoFullscreen = true; } @Override public void onHideCustomView() { if (!isVideoFullscreen) { return; } Log.w("EXIT FULLSCREEN"); activityVideoView.setVisibility(View.GONE); activityVideoView.removeView(videoViewContainer); activityNonVideoView.setVisibility(View.VISIBLE); videoWindow.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); videoViewContainer = null; videoCallback.onCustomViewHidden(); isVideoFullscreen = false; } public boolean onBackPressed() { onHideCustomView(); return isVideoFullscreen; } }
WebViewActivity
public class WebViewActivity extends BaseActivity { public static final String WEB_VIEW_URL_EXTRA = "URL"; private boolean loadedFirstURL = true; private VideoWebChromeClient mWebChromeClient; @Bind(webview) WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(provideLayoutId()); String url = (String) getIntent().getSerializableExtra(WEB_VIEW_URL_EXTRA);
It works correctly on KitKat , but not on Nougat (I only have two devices that need to be checked): when I click the full-screen view button, it sometimes enters full-screen mode, but more often it βblinksβ and remains not in full-screen mode.
And then, when it really is in full screen mode, the exit button from full screen mode does not work ( onHideCustomView is not called at all)
You can see that I placed the logs and noticed that when a "flash" occurs, onHideCustomView actually called right after onShowCustomView ( "ENTER FULLSCREEN" and then "EXIT FULLSCREEN" ), I donβt understand why.
Thanks so much if anyone can point me to a solution
source share