android - 如何使按钮在视频 View 中可见 "OnPreparedListener"方法

标签 android button android-videoview

我的 Activity 中有播放按钮和视频 View 。在 xml 中,我将按钮设为不可见。在 java 代码中,我试图让它可见。

在视频 View 的 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>

最佳答案

而不是这个::

 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);
            }
        });

希望这有帮助:)

关于android - 如何使按钮在视频 View 中可见 "OnPreparedListener"方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17088961/

相关文章:

android - 如何从 rtsp 流中截取 Android 的 VideoView 的屏幕截图?

java - 如何迭代嵌套类?

javascript - 为什么我的按钮无法前进到下一个问题?

Android:自定义字体适用于 TextView,不适用于 Button

iOS:为什么我不能以编程方式为按钮设置框架?

android - 如何在播放前在videoview中设置预览图像

java - 如何将点击播放/暂停添加到 VideoView?

android - 没有gradle的缓存版本-不禁用离线模式

javascript - signinwithphonenumber 身份验证失败

android - 错误 : Unknown option '--no-crunch' - AAPT error