Swipe Refresh Activity
Volley Library Registration Log-in Log-out
Network Connectivity Services
Firebase Authentication - Google Login
Android Notification
Using Google reCAPTCHA
Android Social
Integrating Google Sign-In
Integrating LinkedIn
Integrating Twitter
Android Versions
Android Versions
Android KitKat
Android Lollipop
Android Marshmallow
Android Nougat
Android Oreo
Android Pie
Android 10
Android Misc
Android Device Manager
Android Studio
Android Auto
Android File Transfer
Android Messages
Android TV
Android Screenshot
Android Pay
Android Watch
Android Phones
Android Tablets
Android Find My Phone
Android One
Android Wear OS
Android Data Recovery
Android Antivirus
Android x86
Android vs iPhone
Emulator for PC
Android File Manager
Android ad blocker
Android Podcast App
Fortnite Epic Game
FaceTime for Android
ShowBox for Android
Android App Store
Virus Removal for Android
Clear cache Android
Root Android Device
Android Screen Recorder
Block Number on Android
Canon printer app for Android
Wireless HP printer app for Android
How to Update Android
iMessage for Android
iCloud for Android
Call Recorder for Android
Videoder Android Apk
YouTube Video Downloader for Android
Airdrop for Android
RoboKiller for Android
Clean my Android Phone
How to hide apps, files, and photos on Android
Best weather apps with widgets for Android
File Transfer for Mac
Mobdro for Android
Android Screen Mirroring
Stock market apps
turn On or Off safe mode
Best browsers for Android
Best clocks for Android
Best email apps for Android
Music player for Android
Android smartwatch for women
Best keyboard for Android
Best messaging app for Android
Device cleaner and booster for Android
Wi-Fi calling on Android
Google Assistant app for Android
How to delete apps on Android
Norton Security and Antivirus for Android
Radio apps for Android
Stock Android
Skype for Android
How to transfer contacts from Android to iPhone
Alexa app for Android
Best Casino Games for Android
Volume booster for Android
How to update apps on Android
Epson Print Enabler for Android
Printer apps for Android
Android Beam
Paranoid Android
Do Not Disturb in Android
How to get Android Messages on PC
Android Dark Mode
QVC app for Android
Weather Underground app
What is NFC on Android
Screen time Android
Search by Image: Google Reverse Image Search
How to record screen on Android
How to split screen on Android
Reddit app for Android
TweakBox for Android
Best PS2 Emulators for Android
Pop-up Blocker in Android
Android Easter Egg
Drudge report Android apps
3DS Emulator Android
Terrarium TV App for Android
Best Android Cleaner Apps
Spectrum TV App for Android
Android 11
Radar Detector Apps
Hotspot apps for Android
How to Transfer Contacts from iPhone to Android
Amazon app store for Android
Hangouts App for Android
Omegle Video Chat on Android
Outlook App for Android Mobile
Animoji for Android
What is content://com.android.browser.home/
Firefox for Android
Movie Apps for Android
POF Free Dating App for Android
PS4 Remote Play for Android
Best Android Games
Best Android TV Boxes
How to Clear Cookies on Android
How to Reset Android Phone
Malwarebytes for Android
How to Find Wi-Fi Password on Android
How to Install APK on Android
How to Unlock Android Phone
How to Block Text Messages on Android
How to Recover Deleted Text Messages and Photos on Android
How to Remove Previously Synced Google Account from Android
How to Transfer Contacts from Android to Android
How to Set up Voicemail on Android
How to Share Wi-Fi Password from iPhone to Android
How to Backup Android Phone
What Version of Android Do I Have
How to Block Website on Android Phone and Computer
Turn on Flash in Chrome
Free Music Downloader mp3 for Android
Who Owns Android
Best Notes App for Android
Barcode scanner apps for Android
How to Connect Android Phone to TV
Best free VPN for Android
Download Google Play Store App for Android
Do AirPods work with Android
How to Download Music from Youtube on Android
How to Empty Trash on Android
How to Print Text Messages from Android
How to Share Location on Android
How to change keyboard on Android phone
How to Hack Wi-Fi password in Android
How to allow or block pop-ups in Chrome browser
How to Enable Cookies on Android
How to see a blocked number and unblock them on Android
How to Track iPhone from an Android Phone
What is my Phone Number on Android
Best Police Radar Detector
How to open TIF or TIFF files on Android
Android Final Year Project Ideas for Computer Science
Android Messages for web
How to Change Font Style in Android Phone
IP Address Format and Table
Best Offline Android Games
Best Camera Apps
Does Apple Watch Work with Android
Fastest Android Emulators
How to Take a screenshot in Android phone
Best Wireless Earbuds for Android
How to Lock Apps on Android
How to turn off Google Assistant on Android
Parental control Android apps
Video player for Android
How to Screen Mirror or Cast Android phone on the TV
Best Learning Apps for Kids
How to Scan QR Code on an Android
How to Find Hidden Apps on Android
How to Delete Downloads on Android
How to Recover Deleted Videos from Android
Best Guitar Learning Apps
Extramarks Learning App
Vedantu Learning App
How to Copy and Paste on your Android
How to Leave a Group Text on Android and iPhone
How to turn off AMBER Alerts on your Android device
How to Move Apps to SD Card on Android
How to delete Preinstalled Apps on Android
How do I Delete Google History on my Android Phone
How to close apps on Android
How to Forward Calls on Android
How to Video Call on Android
How to Delete Gmail Account on Android Phone
How to Get iPhone Emojis on Android
How to Check Airpod Battery on Android
How to download apps on Android
How do I Disable Screen Lock on Android
How to transfer messages from Android to iPhone
How to Unzip or Extract Files on Android Device
How to Block Unknown Numbers on Android
How to Connect Xbox One Controller to Android
How to Make a Conference Call on Android
How to Delete all Emails at once on Android
How to Make Your Number Private on Android
How to make a song as a ringtone on Android
How to Cancel App Subscription on Android
Android MCQ
Android MCQ
Android Interview
Interview Questions
Android Quiz
Android Quiz
Android Video Player Example
By the help of
MediaController
and
VideoView
classes, we can play the video files in android.
MediaController class
The
android.widget.MediaController
is a view that contains media controls like play/pause, previous, next, fast-forward, rewind etc.
VideoView class
The
android.widget.VideoView
class provides methods to play and control the video player. The commonly used methods of VideoView class are as follows:
MethodDescription
public void setMediaController(MediaController controller)
sets the media controller to the video view.
public void setVideoURI (Uri uri)
sets the URI of the video file.
public void start()
starts the video view.
public void stopPlayback()
stops the playback.
public void pause()
pauses the playback.
public void suspend()
suspends the playback.
public void resume()
resumes the playback.
public void seekTo(int millis)
seeks to specified time in miliseconds.
activity_main.xml
Drag the VideoView from the pallete, now the activity_main.xml file will like this:
File: activity_main.xml
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
</RelativeLayout>
Activity class
Let's write the code of to play the video file. Here, we are going to play 1.mp4 file located inside the sdcard/media directory.
File: MainActivity.java
package com.example.video1;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView =(VideoView)findViewById(R.id.videoView1);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);
//specify the location of media file
Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/media/1.mp4");
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
download this android example
You need to run it on the real device (e.g. mobile) to test the application.
Next Topic
Android Mediarecorder Example