Enabling HTML5 video playback in android WebView?

前端 未结 2 781
死守一世寂寞
死守一世寂寞 2020-12-16 14:55

I am building a simple webview application which is now displaying a website filled with short video clips, using the HTML5 video player. Everything runs ok in the default a

相关标签:
2条回答
  • 2020-12-16 15:32

    I got success to show video using html5 video tag using the following code:

    mainWebView.setWebChromeClient(new WebChromeClient());
    
    android:hardwareAccelerated="true"
    
    0 讨论(0)
  • 2020-12-16 15:33

    I know from a previous project we did that you need to use the WebChromeClient to get HTML5 video to play. (And this also gives you hardware accelerated support too - providing you also set the flags on your activity).

    Use:

            mainWebView.setWebChromeClient(new WebChromeClient());
    

    Put that before you set the setWebViewClient. You can override the WebChromeClient to intercept any events you need to handle.

    And in your AndroidManifest.xml within your activity definition, add:

    android:hardwareAccelerated="true"
    

    The following quote is from this SDK Page (scroll down to HTML5 Video support)

    In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient.

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