Android tutorial - Video Player Android - android app development - android studio - android development tutorial
android development tutorial
- VideoView is a customized component which is available in Android and it's the combination of MediaPlayer and SuffaceView which help you to play a video more easily.
- By the help of MediaController and VideoView classes, we can play the video files in android.
Media Controller class:
- Android provides many ways to control playback of audio/video files and streams. One of this way is through a class called MediaPlayer.
- Android is providing MediaPlayer class to access built-in mediaplayer services like playing audio,video e.t.c.
- In order to use MediaPlayer, we have to call a static Method create() of this class. This method returns an instance of MediaPlayer class. Its syntax is as follows −
- The android.widget.MediaController is a view that contains media controls like play/pause, previous, next, fast-forward, rewind etc.
android programming - android software - android emulator
- The android.widget.VideoView class provides methods to play and control the video player. The commonly used methods of VideoView class are as follows:
|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.|
- Drag the VideoView from the pallete, now the activity_main.xml file will be like below:
- Let's write the code to play the video file. Here, we are going to play 1.mp4 file located inside the sdcard/media directory.