Android Study Notes: mediaplayer 1

Source: Internet
Author: User

Mediaplayer Lifecycle

<1> Android mediaplayer provides the audio and video playback functions. On the android interface, the app music and video are used.ProgramAll are implemented by calling mediaplayer.

Mediaplayer is implemented at the underlying layer based on the opencore (packetvideo) Library. To build a mediaplayer program, the upper layer also contains inter-process communication and other content, the basis for inter-process communication is the Binder Mechanism in the basic Android library.

<2> when a mediaplayer object is created or the reset () method is called, it is in idle state and the release () method is called.

<3> when a mediaplayer object is no longer used, it is best to use the release () method to release it to an end state to avoid unnecessary errors.

When the mediaplayer object is in the end state, it cannot be used.

<3> when a mediaplayer object is in idle state after it is created, it is in preparation state if it is created using the CREATE () method.

<4> Any mediaplayer object must be in preparation before playing.

<5> to start playing a mediaplayer object, you must call the START () method successfully. You can use the isplaying () method to determine whether the video is being played.

<6> when a mediaplayer object is being played, you can pause or stop it. Pause () is used to pause the video and stop () is used to stop the video.

The START () method can be used to resume playing when the player is in the paused state. However, you must call the pause () method to make the player in the prepared state, and then start () method to start playing.

<7> you can use the setlooping (Boolean) method to set whether to play cyclically.

 

Common mediaplayer Methods

 

 

Playing music on Android is easy:

 
Mediaplayer media = new mediaplayer (); // constructs the object media. setdatasource ("/sdcard/boys.mp3"); // sets the file path media. prepare (); // prepare media. start (); // start playing

 

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.