how to add music at the starting of your app

hello friends,
i want to start a music(for 10 sec) in my app when the app is started.
so i made a method
mp = MediaPlayer.create(MainActivity.this, R.raw.clipname);
mp.setOnCompletionListener(new OnCompletionListener() {

public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
now can u tell me where to call this method so that it is played only once in the starting…
*my app is using local html pages in webview

If you call that method on the onCreate method of your starting Activity, it should work.

what about creating a thread and using a timer…?is that a good approach?

It can be done. But it’s a little overkill if you just want to play a music on the start. A timer would only be useful if you need to start the playback after some delay.

Just use a handler and postDelayed () exactly like we did the other day for your interstitial “adTimer” and call stop() on the MediaPlayer object after 10 seconds. Declare your class-level member variables at the top exactly like we did with the adTimer. As far as making it play only the first time the app is opened, you’ll need to write an entry in SharedPreferences and then check if that value exists before calling your playSound() method in onCreate. If I have time in a little while, I’ll give you a working example.

musicTimer= new Runnable()
public void run()
// mp.release(); if you are done using this sound for the rest of the activity
musicHandler.postDelayed(musicTimer, 10 * 1000);

wow!!..thanks man you are just great…!!..and by first time i meant, every time user opens the application from clicking the icon. jaise if he returns while he is multitasking, then the music should not be played.and for user convenience i am thinking to provide the options for enabling or disabling sounds in settings menu

Ok, if you want to stop the music 10 seconds after the user comes back to your app after doing something else, you’ll want to override onResume() and do it there instead of onCreate();

Yes you can add starting music to your apps for this use an open event handler on your apps on the first tab/window and then use the API to play a sound.
Now the app is opened with a sound.