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:
-
Set resource address to network address
-
When you are ready to load the network resources, the network is not good or bad, so use asynchronous preparation
Player.prepareasync ();
-
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