我有一个简单的布局,其中包含一个FrameLayout用于全屏显示视频和一个WebView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
</FrameLayout>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
WebView可以显示定义了视频的简单html5页面。
onShowCustomView方法的主体如下:
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, Gravity.CENTER);
frameLayout.removeAllViews();
frameLayout.addView(view, layoutParams);
frameLayout.setVisibility(View.VISIBLE);
}
如何从onShowCustomView获得视频对象? 当我尝试获取framelayout的focus child并将其转换为VideoView时,我会得到一个ClassCastException(我有一个HTML5VideoFullScreen对象)。
请帮忙解决。