android电视 全屏模式,iframe视频不会在Android网页视图中进入全屏模式

您将需要创建一个自定义WebChromeClient来处理两个版本的onShowCustomView(这个回调的新版本在API级别14中引入)以及onHideCustomView.基本上会发生什么,当您尝试播放全屏视频时,您将获得视频视频的一些变化.您需要将其附加到全屏FrameLayout,并将其粘贴到布局层次结构的根目录以覆盖整个屏幕.一旦完成,你需要再次删除它.

这是一个我用来播放视频的版本

private class DerpChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener,MediaPlayer.OnErrorListener {

//@Override

public void onShowCustomView(View view,int requestedOrientation,CustomViewCallback callback) {

log.warn("onShowCustomView");

showCustomView(view,callback);

}

private View mVideoProgressView;

@Override

public void onHideCustomView() {

super.onHideCustomView();

activity.removeFullscreenView();

webView.setVisibility(View.VISIBLE);

try {

mCustomViewCallback.onCustomViewHidden();

} catch (NullPointerException npe) {

// occasionally Android likes to freak out and throw an unhandled NPE if it can't play the video

// therefore we are not going to do anything but eat this exception so it fails gracefully

}

mCustomView = null;

mVideoView = null;

}

@Override

public void onShowCustomView(View view,CustomViewCallback callback) {

super.onShowCustomView(view,callback);

log.warn("onShowCustomView");

showCustomView(view,callback);

}

private void showCustomView(View view,CustomViewCallback callback) {

if (mCustomView != null) {

callback.onCustomViewHidden();

return;

}

mCustomView = view;

mCustomViewCallback = callback;

webView.setVisibility(View.GONE);

if (view instanceof FrameLayout) {

if (((FrameLayout)view).getFocusedChild() instanceof VideoView) {

mVideoView = (VideoView)((FrameLayout)view).getFocusedChild();

}

}

view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));

view.setBackgroundColor(Color.BLACK);

activity.displayFullscreenView(view);

}

@Override

public boolean onConsoleMessage(ConsoleMessage cm) {

log.warn("Console Message: " + cm.message() + " on line " + cm.lineNumber() + " of " + cm.sourceId());

return super.onConsoleMessage(cm);

}

@Override

public void onProgressChanged(WebView view,int newProgress) {

super.onProgressChanged(view,newProgress);

if (newProgress < 100) {

if (loadingProgress.getVisibility() == ProgressBar.GONE) {

loadingProgress.setVisibility(ProgressBar.VISIBLE);

}

loadingProgress.setProgress(newProgress);

} else if (newProgress >= 100) {

loadingProgress.setVisibility(ProgressBar.GONE);

}

}

@Override

public View getVideoLoadingProgressView() {

if (mVideoProgressView == null) {

LayoutInflater inflater = LayoutInflater.from(KnowledgeBaseFragment.this.getActivity().getApplicationContext());

mVideoProgressView = inflater.inflate(R.layout.video_loading_progress,null);

}

return mVideoProgressView;

}

@Override

public boolean onError(MediaPlayer mp,int what,int extra) {

// TODO Auto-generated method stub

return false;

}

@Override

public void onCompletion(MediaPlayer mp) {

this.onHideCustomView();

}

}

请注意,我在片段中进行此操作,因此为了使其真正全屏,我必须将其与活动紧密耦合,以便将FrameLayout附加到整个视图层次结构的根目录,而不仅仅是片段.

以下是这些功能:

@Override

public void displayFullscreenView(View customView) {

parentLayout.addView(customView);

this.customView = customView;

}

@Override

public void removeFullscreenView() {

if (customView != null) {

customView.setVisibility(View.GONE);

parentLayout.removeView(customView);

}

customView = null;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值