Android Video Player series (II)-VideoView and androidvideoview

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.