在 BottomSheetDialogFragment 中使用 VideoView 时,视频始终在顶部加载

While using VideoView in BottomSheetDialogFragment, Video is loading always at the top

我想在高度为 140dp 的 BottomSheetDialogFragment 中的 VideoView 中加载视频,但是当我打开对话框时,视频正在屏幕顶部播放

BottomSheetDialogFragment:

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">

<VideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="140dp" />

<TextView
    android:id="@+id/txt_message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:layout_gravity="center"
    android:layout_marginTop="23dp"
    android:layout_marginLeft="19dp"
    android:layout_marginRight="19dp"
    android:textColor="@color/black"
    android:letterSpacing="0.01"
    android:text="dummy_large_text"
    android:lineSpacingExtra="6.5sp"
    tools:ignore="RtlSymmetry"
    tools:targetApi="lollipop" />

<Button
    android:id="@+id/btn_back"
    android:layout_width="match_parent"
    android:layout_height="60.2dp"
    android:textColor="@color/white"
    android:layout_marginTop="21.5dp"
    android:text="@string/back"
    android:background="@color/colorPrimary"
    android:letterSpacing="0.09"
    tools:targetApi="lollipop" />

 </LinearLayout>

Java代码:

holder.videoView.setVideoURI(Uri.parse(imgPathFile + File.separator + dataModels.get(position).getFileName()));
holder.videoView.setMediaController(new MediaController(context)); //sets MediaController in the video view
holder.videoView.requestFocus();//give focus to a specific view
holder.videoView.start();//starts the video

按照我导师的建议,我使用外部库解决了这个问题 来自 GitHub.

的 universalvideoview

如果有人想在他们的项目中添加 VideoView 然后使用下面的库

https://github.com/linsea/UniversalVideoView