Android Video Player series (II)-VideoView and androidvideoview
Recently, I have been learning video-related knowledge. Now I am working step by step. If you have the same requirements, you can follow the steps to facilitate learning.
The previous section mentioned that you can use a system player and a browser to play local and online videos, but this is not enough to meet our needs. Fortunately, the android system provides us with a very convenient system API-VideoView to support more convenient operations.
VideoView provides good API support and provides basic video playback methods. The main methods are as follows:
Start (): start playing
Pause (): pause playback
Resume (): Restore
GetDuration (): Get the video Length
GetCurrentPosition (): gets the current playback position
SeekTo (int msec): Unit: milliseconds, jump to the corresponding location
IsPlaying (): indicates whether the video is being played.
SetVideoURI (Uri uri): sets the playback source.
SetVideoPath (String path): sets the playback source.
SetOnPreparedListener (MediaPlayer. OnPreparedListener l): Listener video resource Loading completed
SetOnCompletionListener (OnCompletionListener l): Listener video playback complete
SetOnErrorListener (OnErrorListener l): An error occurred while listening for video playback.
Of course, these are basic operations on video playback. The android system also provides the video control API MediaControllder, which can be used with VideoView to control and call video playback.
VideoView. setMediaController (MediaController controller) can be used to control the functions of video playback, pause, fast forward, last, next, and drag Fast forward. MediaController has two important methods:
IsShowing (): whether the control bar is displayed
SetPrevNextListeners (View. OnClickListener next, View. OnClickListener prev): The last listener.
One of the details is that the previous and next buttons are hidden by default. They are displayed only after the previous listener is set. See the source code:
The listener must be set for display.
The following is a small case of VideoView:
Reference: http://www.jianshu.com/p/98a10353494c