package tts.indeed.com.mediaplayer;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends Activity {

MediaController mediaController;
VideoView videoView;
Button openButton;
Uri current;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

videoView =(VideoView)findViewById(R.id.videoView1);
openButton = (Button) findViewById(R.id.openButton);

//Creating MediaController
mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);

openButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();

intent.setType(“video/*”);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, “Video File to Play”), 0);
}
});
}

public void startPlayback()
{
//specify the location of media file
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController);
videoView.setVideoURI(current);
videoView.requestFocus();
videoView.start();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
Uri sourceUri = data.getData();
current = sourceUri;
startPlayback();
}
}
}

}

<?xml version=”1.0″ encoding=”utf-8″?>
<android.widget.RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
xmlns:app=”http://schemas.android.com/apk/res-auto”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
tools:context=”tts.indeed.com.mediaplayer.MainActivity”>

<VideoView
android:id=”@+id/videoView1″
android:layout_width=”match_parent”
android:layout_height=”300dp”
android:layout_below=”@+id/openButton”
android:layout_alignParentLeft=”true”
android:layout_alignParentStart=”true”
android:layout_marginTop=”50dp” />

<Button
android:id=”@+id/openButton”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_alignParentStart=”true”
android:layout_alignParentTop=”true”
android:layout_marginTop=”45dp”
android:text=”Open” />

</android.widget.RelativeLayout>

Click here for the files: https://drive.google.com/open?id=1g6p5YcCQptoypHMtIUxMbAFityHQX8iD