赞
踩
使用 TBS x5内核WebView实现视频全屏播放 支持快进 改变屏幕亮度 和音量调节
webview
的时候添加配置mWebView.setWebChromeClient( new com.tencent.smtt.sdk.WebChromeClient(){ /*** * 视频播放相关的方法 * **/ @Override public View getVideoLoadingProgressView() { FrameLayout frameLayout = new FrameLayout(MovieWatchActivity.this); frameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); return frameLayout; } @Override public void onShowCustomView(View view, IX5WebChromeClient. CustomViewCallback customViewCallback) { //播放时横屏幕,如果需要改变横竖屏,只需该参数就行了 showCustomView(view, customViewCallback); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } @SuppressLint("SourceLockedOrientationActivity") @Override public void onHideCustomView() { //不播放时竖屏 hideCustomView(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } });
FrameLayout
/** * webView 实现全屏播放的配置 */ private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback callback) { if (customView != null) { callback.onCustomViewHidden(); return; } this.getWindow().getDecorView(); FrameLayout decor = (FrameLayout) getWindow().getDecorView(); fullscreenContainer = new FullscreenHolder(MovieWatchActivity.this); fullscreenContainer.addView(view, COVER_SCREEN_PARAMS); decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS); customView = view; setStatusBarVisibility(false); customViewCallback = callback; }
/**
* 全屏容器界面
*/
static class FullscreenHolder extends FrameLayout {
public FullscreenHolder(Context ctx) {
super(ctx);
setBackgroundColor(ctx.getResources().getColor(android.R.color.transparent));
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
return true;
}
}
2021 继续努力!~
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。