3

我有一个简单的布局,其中一个 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 的焦点子并将其转换为 VideoView 时,我得到一个 ClassCastException(我在那里有一个 HTML5VideoFullScreen 对象)。

请帮忙。

4

1 回答 1

1

I've been noticing that starting with Ice Cream Sandwich (Android 4.0), a VideoView isn't used for video playback. There's new objects like the HTML5VideoFullScreen you mentioned, which have their own MediaPlayers instead of using the default VideoView.

Why do you need the VideoView?

于 2012-05-31T15:42:21.507 回答