Android VideoView example tutorial to play online videos via HTTP URL

Create online video player using VideoView to stream videos online in android app project with source code download.

VideoView widget is used to play online videos inside android app via http or https URL. VideoView widget gives us the ability to play media files through internet, means if you have a website and you have a website promotional video which you want to display on your android activity then VideoView widget helps you to play you online server located video through its http url without using YouTube or any other website as embedded platform. App developer can directly play their own videos in android app. So here is the complete step by step tutorial for Android VideoView example tutorial to play online videos via HTTP URL.

android-project-download-code-button

What we are doing in this project : We have uploaded a sample 3gp format video on our Android-Examples.com server and playing that video inside android activity.[ Note : First video will completely download inside your phone then it will play. ]

Android VideoView example tutorial to play online videos via HTTP URL.

Note : Please add internet permission inside AndroidManifest.xml file because without internet permission your app will not able to access device or emulator internet connection.

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

Code for MainActivity.java file.

 package com.videoview_android_examples.com;

import android.app.Activity;
import android.os.Bundle;
import android.widget.VideoView;

public class MainActivity extends Activity {

 VideoView videoview ;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 videoview = (VideoView) findViewById(R.id.videoView1);

 videoview.setVideoPath(
 "https://www.android-examples.com/wp-content/uploads/2016/01/sample_video.3gp");

 videoview.start();
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.videoview_android_examples.com.MainActivity"
 android:background="#02bf95" >

 <VideoView
 android:id="@+id/videoView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true" />

</RelativeLayout>

Code for AndroidManifest.xml file.

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.videoview_android_examples.com"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <uses-permission android:name="android.permission.INTERNET" />
 
 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

Screenshot:

Android VideoView example tutorial to play online videos via HTTP URL

Click here to download Android VideoView example tutorial to play online videos via HTTP URL project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *