如何在Android全屏模式下访问视频对象

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的focus child并将其转换为VideoView时,我会得到一个ClassCastException(我有一个HTML5VideoFullScreen对象)。
请帮忙解决。
1个回答

1
我注意到从冰淇淋三明治(Android 4.0)开始,VideoView不再用于视频播放。有新的对象,比如你提到的HTML5VideoFullScreen,它们有自己的MediaPlayer而不是使用默认的VideoView。
你为什么需要VideoView?

嗨 - 感谢您的回答。我需要控制视频对象 - 主要是捕获onpause和onstop事件。 - durzy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接