我在自定义对话框中有一个VideoView,我正在为VideoView立即创建一个媒体控制器,并将其分配给代码中的VideoView,但控制器实际上并不会出现在视频中 – 它出现在对话框后面!任何想法如何让控制器上面的视频?
我创建了一个静态对话助手类来帮助构建自定义对话框:
public class DialogHelper { public static Dialog getVideoDialog(Context context,Uri videoLocation,boolean autoplay) { final Dialog dialog = getBaseDialog(context,true,R.layout.dialog_video); ((Activity)context).getWindow().setFormat(PixelFormat.TRANSLUCENT); final VideoView videoHolder = (VideoView) dialog.findViewById(R.id.video_view); videoHolder.setVideoURI(videoLocation); //videoHolder.setRotation(90); MediaController mediaController = new MediaController(context); videoHolder.setMediaController(mediaController); mediaController.setAnchorView(videoHolder); videoHolder.requestFocus(); if(autoplay) { videoHolder.start(); } videoHolder.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { dialog.dismiss(); } }); return dialog; } /** * Creates a simple dialog Box with as many buttons as you want * @param context The context of the dialog * @param cancelable whether the dialog can be closed/cancelled by the user * @param layoutResID the resource id of the layout you want within the dialog * * @return the dialog */ public static Dialog getBaseDialog(Context context,boolean cancelable,int layoutResID) { Dialog dialog = new Dialog(context,R.style.Theme_PopUpDialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(cancelable); dialog.setCanceledOnTouchOutside(cancelable); dialog.setContentView(layoutResID); return dialog; } }
所以在我的活动中,我只需要创建我的对话框:
Dialog videoDialog = DialogHelper.getVideoDialog(context,Uri.parse("http://commonsware.com/misc/test2.3gp"),true); videoDialog.show();