Android WebView Playing HTML5/h.264/mp4 Video, How to get at the MediaPlayer

前端 未结 2 408
我寻月下人不归
我寻月下人不归 2020-12-17 10:19

I have an Activity which is a WebView. I have a WebChromeClient inside it. Inside that, there are several callbacks which are meant t

相关标签:
2条回答
  • 2020-12-17 10:44

    There is no way to access the MediaPlayer without reflection - the WebViewClient and WebChromeClient do not intentionally expose it. And you are correct in saying that using reflection could cause you to break your app or the WebView as the code can vary across Android versions, and even across OEMs.

    If you would like to do this, you will have to locate the instance of HTML5VideoView that corresponds to your video element. This object creates and maintains an instance to the MediaPlayer as "mPlayer". Please see https://github.com/android/platform_frameworks_base/blob/jb-mr2-release/core/java/android/webkit/HTML5VideoView.java.

    0 讨论(0)
  • 2020-12-17 10:47

    in your class

    private class MyWebChromeClient extends WebChromeClient 
                                    implements ..... MediaPlayer.onCompletion {
    }
    

    adding

    @Override
    public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
        mp.release();           
    }
    

    gets rid of the error messages for me after the webview closes.

    Now if only I could get the webview to play/stream vimeo videos :(

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