Do in this way:
public class MainActivity extends Activity
{
.... //variables declarations here
VideoView videoView;
MediaController mc;
protected void onCreate(Bundle savedInstanceState)
{
........
......
videoView = (VideoView)findViewById(R.id.videoView1);
mc = new MediaController(this);
mc.setAnchorView(videoView);
ImageButton btn1 = (ImageButton)findViewById(R.id.galleryPicker);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"),PICK_FROM_GALLERY);
}
} );
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode != RESULT_OK) return;
if (requestCode == PICK_FROM_GALLERY)
{
Uri mVideoURI = data.getData();
videoView.setMediaController(mc);
videoView.setVideoURI(mVideoURI);
videoview.requestFocus();
videoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
}
}