Playing HTML5 video on fullscreen in android webview

后端 未结 8 2119
迷失自我
迷失自我 2020-11-22 10:23

Well, I\'ve been searching few days already, how to display HTML5 video in full-screen mode on android WebView.

I managed to play HTML5 videos on my webview. Problem

8条回答
  •  死守一世寂寞
    2020-11-22 10:57

    Cprcrack's answer works very well for API levels 19 and under. Just a minor addition to cprcrack's onShowCustomView will get it working on API level 21+

    if (Build.VERSION.SDK_INT >= 21) {
          videoViewContainer.setBackgroundColor(Color.BLACK);
          ((ViewGroup) webView.getParent()).addView(videoViewContainer);
          webView.scrollTo(0,0);  // centers full screen view 
    } else {
          activityNonVideoView.setVisibility(View.INVISIBLE);
          ViewGroup.LayoutParams vg = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT);
          activityVideoView.addView(videoViewContainer,vg);
          activityVideoView.setVisibility(View.VISIBLE);
    }
    

    You will also need to reflect the changes in onHideCustomView

提交回复
热议问题