How to Play HTML5 video and YouTube Video within Android WebView?

前端 未结 4 1729
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 08:20

I am trying to play html5 video and youtube video within android webview, but can\'t display video on android webview screen. and play this video.

I have used below

4条回答
  •  失恋的感觉
    2021-01-01 08:36

    I used html5webview to solve this problem.Download and put it into your project then you can code just like this.

    private HTML5WebView mWebView;
    String url = "SOMEURL";
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mWebView = new HTML5WebView(this);
        if (savedInstanceState != null) {
                mWebView.restoreState(savedInstanceState);
        } else {
                mWebView.loadUrl(url);
        }
        setContentView(mWebView.getLayout());
    }
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mWebView.saveState(outState);
    }
    

    To make the video rotatable, put android:configChanges="orientation" code into your Activity for example (Androidmanifest.xml)

    
    

    and override the onConfigurationChanged method.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
    }
    

提交回复
热议问题