Playing sounds in Android
Copy your sounds in raw/ folder in res/ . If you do not have raw/ folder then make one by right clicking on res/ folder, click on Android resource directory and then giving directory name as “raw” and selecting resource type as “raw” and then copy your sounds in this directory.
The following code starts a sound in onCreate() method and handle its lifecycle:
- Starts the sound on onCreate().
- Pause the Sound on onPause() and getting its seek position.
- Playing the sound on onResume() from where it was stopped at onPause().
- Release the resources associated with MediaPlayer object on onDestroy().
- public class MainActivity extends Activity {
- private static MediaPlayer mp ;
- private int musicSeekLength = 0;
- @Override
- protected void onCreate() {
- startSound();
- }
- @Override
- protected void onResume() {
If you have any queries related to Android Programming than you can ask your query at our Android Developer Forum.
Advertise on APSense
This advertising space is available.
Post Your Ad Here
Post Your Ad Here
Comments