Android Video Player Example
Last updated Nov 01, 2019In Android VideoView widget is used to play the videos. It can load files from various sources.
android.widget.VideoView
With Help of MediaController class Play the videos. MediaController contains media controls like play,pause,previous,next etc...
android.widget.MediaController
VideoView in XML file
|
VideoView class methods
setMediaController (MediaController controller)
|
Use this method to set the MediaController object to VideoView |
public void setVideoURI(Uri uri) |
Sets the Video file Uri to VideoView |
public void start() |
Use to start the VideoView to play the Video |
public void stopPlayback() |
Use to stops the playback |
public void suspend() |
suspends the playback |
public void resume() |
resume the playback |
public void seekTo(int millis) |
seeks the current video to specified time |
getDuration() |
get the Video duration |
getCurrentPosition() |
get the current position of the video |
Methods of MediaController class
setAnchorView(View view) |
setAnchorView is used to view to which controller is to anchored |
show() |
show the controller on the screen |
show(int timeout) |
set the time to show the controller |
hide() |
hide the controller from the screen |
Code in Java
public class PlayetActivity extends Activity {
|
Play the View from Raw Folder
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.VideoName);
Play the video from external storage
Uri uri = Uri.parse(Environment.getExternalStorageDirectory()+"");
Article Contributed By :
|
|
|
|
846 Views |