如何解决在BottomSheetDialogFragment中使用VideoView时,视频始终加载在顶部
我想将视频加载到高度为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的通用视频视图。
如果有人想在他们的项目中添加VideoView,请使用下面的库
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。