All TalkersCode Topics

Follow TalkersCode On Social Media - A Social Media Network for developers Join Now ➔

How To Play Video In Android From URL

Last Updated : Mar 11, 2024

How To Play Video In Android From URL

In this article we will show you the solution of how to play video in android from url, for showing the video in our android application we will use the widget named VideoView widget.

The VideoView widget is perfectly capable of playing media files, and the formats supported by the VideoView are 3GP and MP4.

With the help of VideoView you we can play media files from the local storage and also from the internet. We will try to implement this project using Java language.

Before moving to next, please follow every step from beginning to the end. if you don’t follow the steps then it will be difficult for you to learn “How to play video in android from URL.

Step By Step Guide On How To Play Video In Android From URL :-

Xml Code

<?xml version="1.0" encoding="utf-8"?>
<!-- adding VideoView to the layout -->
android:layout_centerInParent="true" />
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
// Your Video URL
String videoUrl = "";
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
  1. In the first step we will create a new project, On the Welcome screen of Android Studio, just click on Create New Project and If by chance you have a project already opened, then kindly Go to File > New > New Project. Then select whatever Project Template window, select Empty Activity and then click Next. kindly enter your App Name in the Name field and then select Java from the Language drop-down menu. Adding the Internet Permission
  2. Kindly Navigate to app > manifest > AndroidManifest.xml and then internet permission to that file as I have done below. <uses-permission android:name="android.permission.INTERNET"/>
  3. Kindly Navigate to the app > res > layout > activity_main.xml and then add the below code to that file. Above is the code for the activity_main.xml file.
  4. Now Go to the file and kindly refer to the following code. Above is the code for the file. Comments are actually added inside the code to understand the code even more in detail.

Conclusion :-

That’s it. This is the most simple and easy way to play video on your android application with the help of a URL.

You can implement the code by yourself or by copying our source code.

I hope this article on how to play video in android from url helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Anjali

Experienced Computer Programmer with a broad range of experience in technology. Strengths in application development and Object Oriented architecture design, front end programming, usability and multimedia technology. Expert in coding languages such as C, C++ Java, JavaScript, PHP and more.

Follow Anjali On Linkedin 🡪