3

フルスクリーン ビデオと WebView を表示する 1 つの FrameLayout を持つ単純なレイアウトがあります。

<?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

Ice Cream Sandwich (Android 4.0) 以降、ビデオの再生に VideoView が使用されていないことに気付きました。あなたが言及した HTML5VideoFullScreen のような新しいオブジェクトがあり、デフォルトの VideoView を使用する代わりに独自の MediaPlayers があります。

なぜ VideoView が必要なのですか?

于 2012-05-31T15:42:21.507 に答える