zek54
zek54

Reputation: 415

VideoView in CustomDialog Android

I want to play a video in Custom Dialog using VideView, but in the dialog I only get the Title but neither the VideoView nor the button.Please help and is there a better way I can display the video over my Activity than the custom dialog??

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();

Layout of the custom dialog

<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>

Upvotes: 2

Views: 2749

Answers (1)

Aditya Vyas-Lakhan
Aditya Vyas-Lakhan

Reputation: 13555

Try this it will work

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();

Upvotes: 1

Related Questions