VideoView 在自定义对话框中 Android

VideoView in CustomDialog Android

我想使用 VideView 在自定义对话框中播放视频,但在对话框中我只得到标题,但 VideoView 和 button.Please 都没有帮助,有没有更好的方法可以在我的 Activity 上显示视频而不是自定义对话框??

final Dialog dialog = new Dialog(getActivity());
                    dialog.setContentView(R.layout.introvid);
                    dialog.setTitle("Title...");

                    // set the custom dialog components - text, image and button

                    final VideoView viz = (VideoView) dialog.findViewById(R.id.vid123);
                    Uri vidUri = Uri.parse(feedob);
                    vid.setVideoURI(vidUri);
                    vid.start();

                    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
                    // if button is clicked, close the custom dialog
                    dialogButton.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });

                    dialog.show();

自定义对话框的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

<VideoView
    android:id="@+id/vid123"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />


    <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="Back "
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@+id/vid123"
        />

</RelativeLayout>

尝试一下它会起作用

final Dialog dialog = new Dialog(yourclassname.this);// add here your class name
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.yourxml);//add your own xml with defied with and height of videoview
    dialog.show();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.copyFrom(dialog.getWindow().getAttributes());
    dialog.getWindow().setAttributes(lp);
    uriPath= "android.resource://" + getPackageName() + "/" + R.raw.yourvid;

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    Log.v("Vidoe-URI", uriPath+ "");
    mVideoView.setVideoURI(Uri.parse(uriPath));
    mVideoView.start();