Videoview Android Kotlin Tutorial Example Programmatically

Hello Coders, Welcome to Videoview android kotlin tutorial 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 kotlin example then we will implement it.

Download Source Code For Videoview Android Kotlin

Creating Videoview Android Studio Example

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 kotlin

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

app intro animation video slider android, When you click on Android resource directory, one dialog will open. In Directory name give value as "raw."

Now save your video in the raw directory.

Step 4: Updating MainActivity.kt class : 

Add below code to MainActivity.kt

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 MainActivity.kt

  • 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.

Java Version

Java vesion of this tutorial : Android Videoview Tutorial

So that is all for this videoview android studio kotlin 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...

Leave a Reply

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