2011-8-13 1:18:23
In android, we can play the audio file from the resource.
How to do it ?
Step1:- In your project , create a folder named with 'raw' in res folder (res --- > raw). In that folder copy any mp3 file to play.
Step 2:-
Edit your Java class file
[sourcecode language="java"]
public class MediaPlayerExample extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.test_cbr);
mPlayer.start();
}
}
[/sourcecode]
Now Run the Application.
After the application starts , the media player will starts automatically and song will be played. To stop playing the song use mPlayer.stop();