@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
VideoView v1 = (VideoView) findViewById(R.id.video1);
final MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(v1);
v1.setMediaController(mediacontroller);
v1.setVideoURI(Uri.parse("https://www.w3schools.com/html/movie.mp4"));
v1.requestFocus();
v1.start();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity2">
<VideoView
android:id="@+id/video1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="120px"
android:layout_marginRight="120px"
android:layout_marginTop="120px"
android:layout_marginBottom="120px"
/>
</LinearLayout>
Add Following permission in AndroidManifest.xml File
<uses-permission android:name="android.permission.INTERNET" />