Android VideoView Tutorial With Example

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


Tutorialwing Android VideoView Output Android VideoView Tutorial With example

Tutorialwing Android VideoView Output

Getting Started

VideoView widget can be defined as below –

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

Attributes of Android VideoView Widget

Some of the popular attributes of videoView are –

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

Example of Android VideoView Widget

At first, we will create android application. Then, we will use VideoView widget in this application.

1. Creating New Project

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

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as VideoView. Then, 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. If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit post to create a new project to know steps in detail.

Now, we will modify xml and java file to use android videoView widget 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 res/layout/activity_main.xml file. Then, 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 these widgets in java file in the application.

4. Access VideoView Widget in java file

Open src/main/java/com.tutorialwing.videoview/ file. Then, add below code into it.

package com.tutorialwing.videoview;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

	protected void onCreate(Bundle savedInstanceState) {

		final VideoView videoView = findViewById(;
		if (videoView != null) {
			String path = "android.resource://" + getPackageName() + "/" + R.raw.a;

		final Button button = findViewById(;
		if (button != null) {
			button.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					if (videoView != null) {
						boolean isPlaying = videoView.isPlaying();
						button.setText(isPlaying ? : R.string.pause);

						String msg = getString(isPlaying ? R.string.paused : R.string.playing);
						Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
						if (isPlaying) {
						} else {

In file, we have accessed android videoView widget. Then, we accessed video resource that was stored in res/raw folder. After that, we have set video resource to videoView. At last, we set click listener to button that play/pause video in videoView. If video is already playing, we pause the video. otherwise, we play the video when button is clicked. Method videoView.start() is being called to play the video. Method videoView.pause() is being called to pause the video.

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


Code inside src/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 tutorial on Android VideoView widget.

Leave a Reply