Introduction
Adding video to an Android app can be done just by adding a few lines of code. In this article, I will demonstrate how to embed a video to an Android app. This article will also explain how to control the video by playing, pausing and by seeking back and forth. This is really easy to do.
Steps to embed video in your Android Application
Step 1
Open your Android project and create a new Android project
Step 2
Create a new folder named "raw" in your Android project's "res" folder and place your video file inside the "raw" folder.

You can now see the video content is successfully added into your Android Studio project by viewing the "raw" subfolder under "res" folder.
Step 3
To add a video player in the activity_main.xml layout, go to "Design" tab of your activity_mail.xml. Goto "Widgets" under palette and drag the "VideoView" into your Android Aplication Layout. I have named my VideoView's id as "videoView".
Step 4
Write code to attach video to the VideoView.
On the onCreate() method add the following code,
- VideoView videoView = (VideoView) findViewById(R.id.videoView); //casting to VideoView is not Strictly required above API level 26
- videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.videoclip); //set the path of the video that we need to use in our VideoView
- videoView.start(); //start() method of the VideoView class will start the video to play
Step 5
Run your Application on your physical device or emulator. But you have noticed that there is no controls on that video.
So to add controls on your video, use "MediaController" class.
Add the following lines of code, after the code of setting up the Path to your video.
- MediaController mediaController = new MediaController(this);
- //link mediaController to videoView
- mediaController.setAnchorView(videoView);
- //allow mediaController to control our videoView
- videoView.setMediaController(mediaController);

Emma MeganPosted Jun 25, 2022, 12:05 PM
You made my work easy by showing each step trough images.
James CarterPosted May 26, 2022, 7:50 PM
Good Day, hoping you can help me. I created a Simple App that has a Username/password Sign-in Page and if successful then lands on the Activity_Second.xml page and just says Welcome. How can I instead, load an external M3U Video playlist for which then users can play the video streams with the internal Video Player app on the device? Thank you [email protected]
Dipa MehtaPosted Mar 18, 2020, 10:47 PM
Nice article Shalini..:)