Android VideoView Using Kotlin With Example

Hello Readers! In this post, we are going to learn about android videoView using kotlin in any android application. We will also learn about different attributes of android videoView that can be used to customise this widget.


Tutorialwing Kotlin VideoView Output Android VideoView Using Kotlin

Tutorialwing Kotlin VideoView Output

Getting Started

Android VideoView can be defined as below –

VideoView is subclass of View that are used to display a video file.

Different Attributes of Android VideoView Widget

Some of the popular attributes of videoView are –

Sr. XML Attributes Description
1 android:clickable Sets whether this view is clickable or not
2 android:elevation Sets elevation of the view
3 android:focusable Sets whether this view should take focus or not
4 android:id Sets id of the view
5 android:longClickable Sets whether this view should respond to long click or not
6 android:onClick Sets what to do when this view is clicked
7 android:padding Sets padding of the view
8 android:paddingBottom Sets bottom padding of the view
9 android:paddingEnd Sets padding to right edge of the view
10 android:paddingHorizontal Set padding to left and right edges of the view
11 android:paddingLeft Sets padding to left edge of the view
12 android:paddingRight Sets padding to right edge of the view
13 android:paddingStart Sets padding to left edge of the view
14 android:paddingTop Sets padding to top edge of the view
15 android:visibility Sets visibility of the view

Example of Android VideoView Using Kotlin

At first, we will create android application. Then, we will use videoView using kotlin in the application.

1. Creating New Project in Kotlin

Follow steps below to create new project. Please ignore the steps if you have already created the project.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as VideoView. Then, check Include Kotlin Support and click next button.
3. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button
4. Then, select Empty Activity => click next => click finish.
5. You will get a newly created project successfully if you have followed steps properly.

Since we have a project now, we will modify xml and other files to use videoView using kotlin in the application.

2. Modify values folder

Open res/values/strings.xml file. Then, add below code into it.

	<string name="app_name">VideoView</string>
	<string name="play">Play</string>
	<string name="pause">Pause</string>
	<string name="paused">Paused…</string>
	<string name="playing">Playing…</string>

3. Use VideoView Widget in xml file

Open src/main/res/layout/activity_main.xml file and add below code into it.

<?xml version="1.0" encoding="utf-8"?>




In activity_main.xml file, we have defined VideoView and Button widgets. Now, we will access this widgets in kotlin file. Then, we will perform some operations on it.

4. Access VideoView Widget in Kotlin file

Open src/main/java/com.tutorialwing.videoview/MainActivity.kt file and add below code into it.

package com.tutorialwing.videoview

import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import android.widget.VideoView

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        val videoView = findViewById<VideoView>(
        val path = "android.resource://" + packageName + "/" + R.raw.a

        val button = findViewById<Button>(
            val isPlaying = videoView.isPlaying
            button.setText(if (isPlaying) else R.string.pause)

            val msg = getString(if (isPlaying) R.string.paused else R.string.playing)
            Toast.makeText(this@MainActivity, msg, Toast.LENGTH_SHORT).show()
            if (isPlaying) {
            } else {

We have accessed Button and VideoView using kotlin file (i.e. MainActivity.kt). After that, we have accessed the path of video resource stored in res/raw folder. Note that you will have to create raw folder under main/res folder in the application. We store resources such as audio, video etc. in raw folder.

We have also set click listener in button to play/pause video in the videoView.

Since AndroidManifest.xml file is very important in any android application, we are also going to see the content inside this file.

AndroidManifest.xml file

Code inside main/AndroidManifest.xml file is as below.

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tutorialwing.videoview"

		<activity android:name=".MainActivity">
				<action android:name="android.intent.action.MAIN"/>

				<category android:name="android.intent.category.LAUNCHER"/>


When we run the program, we will get output as shown above.

That’s end of our tutorial on Android videoView using Kotlin.