WebView and HTML5 <video>

后端 未结 13 1666
面向向阳花
面向向阳花 2020-11-22 05:59

I\'m piecing together a cheapo app that amongst other things \"frames\" some of our websites... Pretty simple with the WebViewClient. until I hit the video.

13条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 06:09

    mdelolmo's answer was incredibly helpful, but like he said, the video only plays once and then you can't open it again.

    I looked into this a bit and here is what I found, in case any weary WebView travelers like myself stumble on this post in the future.

    First off, I looked at the VideoView and MediaPlayer's documentation and got a better sense of how those work. I strongly recommend those.

    Then, I looked at the source code to see how the Android Browser does it. Do a page find and go look at how they handle onShowCustomView(). They keep a reference to the CustomViewCallbackand to the custom view.

    With all of that, and with mdelolmo's answer in mind, when you are done with the video, all you need to do is two things. First, on the VideoView that you saved a reference to, call stopPlayback() that will release the MediaPlayer to be used later elsewhere. You can see it in the VideoView source code. Second, on the CustomViewCallback you saved a reference to call CustomViewCallback.onCustomViewHidden().

    After doing those two things, you can click on the same video or any other video and it will open like before. No need to restart the entire WebView.

    Hope that helps.

提交回复
热议问题