Android uses media to play audio

Source: Internet
Author: User

A. Play local music on your phone


1. Create a Mediaplay object

Meiaplayer Player;player = new MediaPlayer ();


2. Resetting the Player object

Player.reset ();


3. Set up resource preparation, start

Player.setdatasource ("Sdcard/a1.mp3");p layer.prepare ();p Layer.start ();


4. Set Pause

Player.pause ();


5. You can continue playing when start is called again

Player.start ();


6. Releasing Resources

if (player! = null) {player.stop ();    Player.release (); Player = null;}


Second, play network music


When playing network music is almost the same as playing local music, just pay attention to the following points:

    1. Set resource address to network address

    2. When you are ready to load the network resources, the network is not good or bad, so use asynchronous preparation

      Player.prepareasync ();
    3. Ready to listen when started using asynchronous preparation, and then start when ready

Player.setonpreparedlistener (New Mediaplayer.onpreparedlistener () {public void onprepared (MediaPlayer MP) {        Player.start (); }    });



This article is from the "laugh at a flower a leaf" blog, please be sure to keep this source http://6445423.blog.51cto.com/6435423/1741992

Android uses media to play audio

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.