如何在视频视图中使按钮可见“OnPreparedListener”方法

时间:2013-06-13 13:58:13

标签: android button android-videoview

我的活动中有播放按钮和视频。在xml中,我使按钮不可见。在java代码中,我试着让它可见。

在视频观看的OnPreparedListener方法中,我试图让它可见。但它不可见。下面是我的代码。

        vvVideos.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                btnPlay.setVisibility(Button.VISIBLE);
            }
        });

XML文件::

<RelativeLayout
    android:id="@+id/bottomll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <VideoView
    android:id="@+id/videoView"
    android:layout_width="fill_parent"
    android:layout_height="150dp"/>

    <Button
        android:id="@+id/btnPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/play"
        android:visibility="gone"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

而不是这个::

 vvVideos.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                btnPlay.setVisibility(Button.VISIBLE);
            }
        });

使用此功能并尝试::

 vvVideos.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                btnPlay.setVisibility(View.VISIBLE);
            }
        });

希望这会有所帮助:)