This article describes how to use VideoView to play a local video. It is relatively simple to use. The MediaController class is added in it to implement more video control functions.
Implementation:
Code;
Layout file:
With VideoView, VideoView is a view with the video playback function, which can be used directly in the layout.
MainActivity:
Package com. multimediademo11videoview; import android. app. activity; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. widget. mediaController; import android. widget. videoView; public class MainActivity extends Activity {private VideoView videoView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. la Yout. activity_main); videoView = (VideoView) findViewById (R. id. videoView);/*** VideoView has fewer functions to control video playback. Specifically, it only has the start and pause methods. To provide more control, * You can instantiate a MediaController and set it to the VideoView controller through the setMediaController method. */VideoView. setMediaController (new MediaController (this); Uri videoUri = Uri. parse (Environment. getExternalStorageDirectory (). getPath () + "/1.mp4"); videoView. setVideoURI (videoUri); videoView. start ();}}
Source code download:
Click to download source code