this is the first time I answer a question in stackoverflow, I only insert a VideoView inside a FrameLayout with same measures both. MediaController will be at the bottom of the FrameLayout. This worked for me:
main_activity.XML:
<FrameLayout
android:id="@+id/frame_layout_video"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="400dp">
<VideoView
android:id="@+id/video_select"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:adjustViewBounds="true"
android:clickable="true"
android:scaleType="centerCrop"
/>
</FrameLayout>
MainActivity.java:
@Override
public void onClick(View v) {
int i = v.getId();
if(i == R.id.select_video){
selectVideo();
}
private void selectVideo(){
//this code is to get videos from gallery:
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("video/*");
startActivityForResult(galleryIntent, GALLERY_REQUEST);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(mVideo);
//mVideo is the VideoView where I insert the video
mVideo.setMediaController(mediaController);
mVideo.pause();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1:
if (resultCode == RESULT_OK) {
mVideoUri = data.getData();
mVideo.setVideoURI(mVideoUri);
mVideo.start();
}
}
}