VideoView in Android Studio

VideoView in Android Studio is used to Display video in Android applications with the help of MediaController and VideoView classes. So, Inside this article, you will learn how to create a simple Video Playing application and how to use classes of VideoView and will clear all the concepts of VideoView in Android Studio.

android. widget.MediaController: It is a View that contains Media Controls like

  1. Play
  2. Pause
  3. Previous
  4. Next
  5. Fast-forward
  6. Rewind

You can also watch YouTube videos from our YouTube channel to implement VideoView in Android Studio.

VideoView In Android - Load Video in Android

Steps for implementing VideoView in android

So, to create a simple application that displays a video. Follow the following steps.

Loading Video From URL

  1. So, First of all, Create a New Project by simply opening up Android Studio and clicking on the “New Project” button.
Creating a new project for VideoView in Android

2. So, Now Select Empty Activity as Application Activity.


3. Next give the name to the application and select the location where to store files of the application. Also, select the Minimum SDK version of the Android Application.

Give Application Name for VideoView

4. So, Open the activity_main.xml file of the res folder. And create a Frame Layout that will contain VideoView Attribute.


5. So, now place the VideoView tag inside Frame Layout.




Give ID to the VideoView as “video” for further use.

6. So, Open (java>com.example.VideoView> file and create an object for VideoView. And initialize VideoView.

VideoView videoView;  
    protected void onCreate(Bundle savedInstanceState) {
        videoView = findViewById(;

7. So, to use VideoView we have MediaController to use it create the object for MediaController.

MediaController mediaController = new MediaController(this);

8. Now set the Media player and set Media Controller for Media View.


9. Now give the URL of the video that you want to display on the Android Application.


The complete file will look like the below file.

package com.example.videoview;


import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    VideoView videoView;
    protected void onCreate(Bundle savedInstanceState) {
        videoView = findViewById(;
        //Create object for media Controller
        MediaController mediaController = new MediaController(this);
        //set media player
        //Set media Controller for media View
        //set Video URL

So, there is two option to display Video

  1. By giving the URL from Internet resources.
  2. From local machine.

Both have a little bit different implementations if you are using URLs from the Internet then some changes in AndroidMenifest.xml must be done.

<uses-permission android:name="android.permission.INTERNET"/>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

So, The first line of the above file refers that asking for users’ permission for access to the INTERNET. And setting ClearTextTraffic to true.


Output of VideoView

So now let us use video from the android resource folder.

Loading Video From Android Resource Folder

1. So, NowGo to the resource directory and create a new “raw” folder.

Creating New Resource Directory
And, select raw as the Resource type and click OK. This will create a folder raw.
Creating New folder for VideoView in Android

Now drop your video inside the raw folder. Make sure that the video name must be in lowercase letters and that no space is used for the file name. We have named it just video.mp4

So, now load the video to the application by changing the URL.


And now run Application

Output of VideoView in Android

During this, an error may occur due to some issues, that error can be tackled by following two steps.

step 1. Clean the project. Build>Clean Project

Error Solution for VideoView

step 2. Invalidate Caches and Restart Android Studio. File>Invalidate Caches / Restart Android Studio

Error Solution

In this article, we have seen how to implement VideoView in Android studio by two methods by internet URLs and from local machines, and How to use MediaController with its classes.

Leave a Comment