Skip to content
Related Articles

Related Articles

How to Play Video from URL in Android?

Improve Article
Save Article
  • Last Updated : 18 Jul, 2021
Improve Article
Save Article

In this article, you will see how to play a video from URL on Android. For showing the video in our android application we will use the VideoView widget. The VideoView widget is capable of playing media files, and the formats supported by the VideoView are 3gp and MP4. By using VideoView you can play media files from the local storage and also from the internet. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Now let’s see the step-by-step implementation of the above application shown in the gif.

Step By Step Implementation

Step 1: Create a new project

So the first step is to create a new project, On the Welcome screen of Android Studio, click on Create New Project and If you have a project already opened, Go to File > New > New Project. Then select a Project Template window, select Empty Activity and click Next. Enter your App Name in the Name field and select Java from the Language drop-down menu.

Step 2: Add the Internet Permission

Navigate to app > manifest > AndroidManifest.xml and the internet permission to that file as shown below.

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

Step 3: Working with the activity_main.xml

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
    <!-- adding VideoView to the layout -->
        android:layout_centerInParent="true" />

Step 4: Working with the

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
    // Your Video URL
    protected void onCreate(Bundle savedInstanceState) {
        // finding videoview by its id
        VideoView videoView = findViewById(;
        // Uri object to refer the 
        // resource from the videoUrl
        Uri uri = Uri.parse(videoUrl);
        // sets the resource from the
        // videoUrl to the videoView
        // creating object of 
        // media controller class
        MediaController mediaController = new MediaController(this);
        // sets the anchor view 
        // anchor view for the videoView
        // sets the media player to the videoView
        // sets the media controller to the videoView
        // starts the video


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!