[Android] Music Player Summary

Source: Internet
Author: User

1. MediaPlayer the files to be played mainly include 3 sources:
A. Resource resources that the user has in advance in the application
For example: MP = MediaPlayer. Create (This, R.raw. Test);
B. media files stored in an SD card or other file path
For example: MP. Setdatasource ("/sdcard/test.mp3");
C. media files on the network
For example: MP. Setdatasource ("Http://www.citynorth.cn/music/confucius.mp3");

2.
Release () frees the resource that the player occupies and should be called as soon as possible when the player is no longer in use.
Reset () Restores the player from the error state and resumes to the idle state.
Prepare () and Prepareasync () provide both synchronous and asynchronous settings for the player to enter the prepare state, and it is important to note that if the MediaPlayer instance was created by the Create method, It is not necessary to call prepare () again before the first start of playback, because the Create method has already been called.
Start () is a way to actually start a file playback.
Pause () and stop () are relatively simple and play a role in pausing and stopping playback.
Seekto () is a positioning method that allows the player to start playing from the specified position, noting that the method is an asynchronous method, which means that the method returns does not mean that the location is complete, especially the network file that is playing, which is triggered when the real location is completed.

3.
MediaPlayer provides several ways to set up different listeners to better monitor the working state of the player in order to handle situations in a timely manner.
such as: Setoncompletionlistener (Mediaplayer.oncompletionlistener listener),
Setonerrorlistener ( Mediaplayer.onerrorlistener listener) and so on, the player needs to be set up to take into account the possible situation of the player set up monitoring and processing logic to maintain the robustness of the player.

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.