Android Video Player Example

Last updated Nov 01, 2019

In Android VideoView widget is used to play the videos. It can load files from various sources.


With Help of MediaController class Play the videos. MediaController contains media controls like play,pause,previous,next etc...



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


get the Video duration


 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 the controller on the screen

show(int timeout)

set the time to show the controller


hide the controller from the screen



Code in Java


public class PlayetActivity extends Activity {  
    protected void onCreate(Bundle savedInstanceState) {  
        VideoView videoView =(VideoView)findViewById(;  
                //Creating MediaController  
        MediaController mc= new MediaController(this);  
              //specify the location of media file  
           Uri uri=Uri.parse(path of the file);          
              //Setting MediaController and URI, then starting the videoView  



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 :


Subscribe For Daily Updates

Flutter Questions
Android Questions