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

前端 未结 4 1714
伪装坚强ぢ
伪装坚强ぢ 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:32

    you haven't added mCustomViewContainer to your view hierarchy

    0 讨论(0)
  • 2021-01-01 08:32

    It worked for me. May help you as well play html videos

    0 讨论(0)
  • 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)

    <activity android:name=".ui.HTML5Activity" android:configChanges="orientation"/>
    

    and override the onConfigurationChanged method.

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
    }
    
    0 讨论(0)
  • 2021-01-01 08:55

    if you are running it on tablet... you add hardwareaccelerated= true in your manifest file and it will certainly work.. also change the sdk version to 11

    0 讨论(0)
提交回复
热议问题