android - 当 listitem 刚刚可见时,recyclerview 中的 Videoview 开始播放
问题描述
我将 VideoView 放入 RecyclerView 但不是直接放入。我使用带有页眉和页脚的容器,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Header -->
<TextView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="HEADER"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:background="@color/design_default_color_primary"/>
<!-- Content -->
<RelativeLayout
android:id="@+id/container_for_infeed"
android:layout_below="@id/header"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- FrameLayout for VideoView -->
<FrameLayout
android:layout_centerInParent="true"
android:layout_gravity="center"
android:id="@+id/display_io_add"
android:layout_width="match_parent"
android:layout_height="350dp">
</FrameLayout>
</RelativeLayout>
<!-- Footer -->
<TextView
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="FOOTER"
android:textSize="120sp"
android:layout_below="@id/container_for_infeed"
android:background="@color/colorAccent"/>
</RelativeLayout>
视频在此布局出现在屏幕上时开始播放,并在滚动到下一个位置时停止。这对我来说不是很好,因为我在同一个容器中也有页脚和页眉,而且它们在 VideoView 之前肯定是可见的。以下是页脚刚特别可见并且视频开始时的滚动位置示例:
这是我的代码:
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.e(TAG, "onPrepared, videoView.getVisibility() = " + videoView.getVisibility());
if (!mp.isPlaying() && (videoView.getVisibility() == View.VISIBLE)) {
mp.start();
}
}
});
问题是为什么 videoView 即使不在屏幕上也被视为可见?为什么每次页脚可见时都会调用 onPrepared ?
解决方案
推荐阅读
- spring-batch - Spring Batch 创建子作业
- c++ - OpenCV stereo_calib 的好结果是什么?
- linux - 我有一个关于 bash 脚本作业问题的问题
- javascript - jquery显示和隐藏工作,但切换不
- python - 将python输出打印到txt文档
- r - flexdashboard 闪亮,无法正确显示
- python - 在另一个方法中调用 ThreadPoolExecutor 时访问类的方法
- sql - 使用共享键插入多个表
- kubernetes - 如何获取 Helm 图表的最新补丁
- java - 使用 Spark Streaming 1.6 读取子文件夹