java - 如何将 VideoView MediaController 添加到底部工作表对话框
问题描述
我正在尝试在底部工作表中添加 Videoview,在框架布局中添加 Videoview,我的问题是 Mediacontroller 没有出现在框架内,它出现在活动中(在底部工作表对话框后面)
底部片段.xml
<?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="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="10dp"
android:background="@drawable/bottom_sheet_bg"
android:orientation="vertical">
<TextView
android:id="@+id/tv_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Video" />
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_below="@+id/tv_video">
<VideoView
android:id="@+id/vv_info_video"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
bottomsheetfragment.java
public class BottomSheetFragment extends BottomSheetDialogFragment {
private static final String TAG = "BottomSheetFragment";
MainActivity activity;
View view;
public static BottomSheetFragment newInstance() {
BottomSheetFragment fragment = new BottomSheetFragment();
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate: ");
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
view = View.inflate(getContext(), R.layout.fragment_bottom_sheet, null);
view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
try{
VideoView videoView = view.findViewById(R.id.vv_info_video);
String videoPath = "android.resource://"+requireActivity().getPackageName()+"/"+R.raw.myvideo;
Uri uri = Uri.parse(videoPath);
videoView.setVideoURI(uri);
MediaController mediaController = new MediaController(getContext());
mediaController.setAnchorView(videoView);
mediaController.setMediaPlayer(videoView);
mediaController.setVisibility(View.VISIBLE);
mediaController.show();
videoView.setMediaController(mediaController);
videoView.start();
}catch (Exception e){
GlobalFunctions.printException(e);
}
return view;
}
@Override
public void setupDialog(Dialog dialog, int style) {
Log.d(TAG, "setupDialog: ");
//dialog.setContentView(view);
}
}
我从片段内的按钮调用这个片段
private void showBottomSheetInfo(){
BottomSheetFragment bottomSheetDialog = BottomSheetFragment.newInstance();
bottomSheetDialog.show(requireActivity().getSupportFragmentManager(), "Bottom Sheet Dialog Fragment");
}
解决方案
推荐阅读
- .net - 如何理解不同版本的框架 (System.*) NuGet 包之间的变化?
- c++ - OpenGL GLM 矩阵/向量未正确初始化
- r - R在R中展平不同长度的嵌套列表(谷歌地理编码API输出)
- flutter - 颤振如何像附加的图像一样向数据列添加颜色,而不导入任何包
- go - 无法找到 Protobuf Unmarshal 错误的解决方案
- reactjs - 如何将 req 值传递到 Sequelize findAll
- swift - MDCOutlinedTextField 未正确显示
- spring-boot - springboot API 抛出 500 错误但没有记录错误
- apache-kafka - 窗口组后的Kafka流总和数据
- ruby - 使用自定义排序首选项对数组进行排序,其中 m 个首选项和 n 个元素为 m < n