VideoView Android Studio Example Programmatically

Hello Coders, Welcome to Videoview android studio example. Today you will learn how to play videos in android’s Videoview from a raw folder of android studio directory.

You will also learn how to play video continuously in this tutorial.

First of all checkout output of this videoview android studio example then we will implement it.

Wait for one minute

If you want to play video from URL, then visit this link. : play video URL android 

How to get maximum benefit from Videoview Android Studio Example

Download Source Code

Try Our App

Download DemoNuts app to learn anytime, anywhere: Click to get Demonuts App

Or search “demonuts” in play store from android mobile device.

Creating Videoview Android Studio Example

If you are using adblocker, then you will not be able to show our site smoothly. For example, you find step 6 after step 1 or similar to this. So please disable adblocker to fully utilize all resources of DemoNuts

Step 1: Create a new project in android studio.

Step 2: Updating activity_main.xml file

Add below code in activity_main.xml file

Step 3: Adding resource directory “raw” under “res” directory.

Now we need to create raw directory, in which we will save our video.

Follow below steps

  • One left left click on res directory at left menu side of android studio.
  • One Right click on res directory, one menu will open.
  • From that menu, follow New-> Android resource directory
Videoview Android Studio Example Tutorial

Create raw directory

  • When you click on Android resource directory, one dialog will open.
  • In Directory name give value as “raw.
Videoview Android Studio Example Tutorial

Naming raw

Now save your video in the raw directory.

Step 4: Updating class : 

Add below code to

Step 5: Updating AndroidManifest.xml file

add internet permission between <manifest>….</manifest> tag.

Note: If you are targeting SDK version above 22 (Above Lollipop)  then you need to ask a user for granting runtime permissions. Check marshmallow runtime permission for more information.

Step 6: Description of

  • Below code

  • will set mediacontrollers(previous, pause, play, next buttons) to videoview.
  • Below code

  • Here you need to update your package name.
  • Replace your package name with com.exampledemo.parsaniahardik.videoviewdemonuts
  • Also replace name of your video with funn in R.raw.funn
  • Following code will run when video has  finished it’s run.

  • As you can see we are using boolean isContinuously to detect which button is pressed, Either “ONCE” or “Continuously “.
  • We are managing isContinuously and starting video on both button’s click method as below.

How to get exact Android example while searching in Google

Click to get Important Google searching tips

So that is all for this videoview android studio example. Thank you for your interest, keep visiting for more cutting edge tutorials. 🙂

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

1 Response

  1. Abioye Adeyinka says:

    Can you help me with the app am working on? Trying to put multiple videos in it an ply each one of it when I click it on the list view. I don’t want sequential playing but for the user to play the video he/she chooses to watch. Thanks

Leave a Reply

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