1

I want to play a video file in videoview which is displayed inside a dialog and on completion the dialog box should be closed . I read about doing it through media controller so I have the following:

final Dialog dialog = new Dialog(MyActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.MyCustomLayoutWithVideoView);
    dialog.show();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    lp.copyFrom(dialog.getWindow().getAttributes());
    dialog.getWindow().setAttributes(lp);
    final VideoView videoview = (VideoView) dialog.findViewById(R.id.videoView);
    Uri uri = Uri.parse(SoundFile);

    **MediaController mc = new MediaController(this);
    videoview.setMediaController(mc);**

        videoview.start();

    videoview.setVideoURI(uri);
    videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) 
{
Toast.makeText(getApplicationContext(), "Msg", Toast.LENGTH_LONG).show();
        }
    });

1) The part of declaring mediacontroller is wrong.. it cant get context, what is the context?

2) How can control this dialog's size based on the maximum height and weight?

1 Answers1

1

You have to use getApplicationContext() to get context. Context represents the environment data. Take a look here: What is Context in Android?

Community
  • 1
  • 1
  • I typed MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoview); videoview.setMediaController(mediaController); and it is working.. which is same!?! How about the dialog's size –  May 05 '15 at 07:55
  • in order to change the size you could set de maxWidth, maxHeight of the MyCustomLayoutWithVideoView xml parent layout – mmark May 07 '15 at 15:50