0

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();
}


}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rezaul Karim
  • 830
  • 8
  • 15
  • It might depend on video player it self in your web code. Have you tried it to play on Chrome and it went full screen? – Antonis Radz Apr 16 '19 at 09:07
  • i have tried with server provided url it works in chrome – Rezaul Karim Apr 16 '19 at 09:48
  • and what is happening when you are trying to go full screen on webview? Have you tried to use different web engine? – Antonis Radz Apr 16 '19 at 09:58
  • log while click on full screen btn: I/chromium: [INFO:CONSOLE(0)] "Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.", source: https://test... I am trying using chrome – Rezaul Karim Apr 16 '19 at 09:59
  • I read somewhere that chromium has some issues with Fullscreen API, you might need to some modification for javascript if have access. Read this https://stackoverflow.com/questions/18966923/fullscreen-via-javascript-on-chrome-for-android-tablets – Antonis Radz Apr 16 '19 at 10:03
  • i have tried that but not working for me – Rezaul Karim Apr 16 '19 at 10:35

1 Answers1

0

try this

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

    @Override
    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(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
        int visibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            visibility = visibility | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_FULLSCREEN;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            visibility = visibility | View.SYSTEM_UI_FLAG_IMMERSIVE;
        }
        StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(visibility);
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

and must set activity configChanges attribute in AndroidManifest.xml

<activity
        android:name=".StreamActivity"
        ...
        android:configChanges="keyboardHidden|orientation|screenSize" />
fancyyou
  • 965
  • 6
  • 7
  • not working.. log while click on full screen btn: I/chromium: [INFO:CONSOLE(0)] "Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.", source: https://test – Rezaul Karim Apr 16 '19 at 09:58