Jordan Cheeks
Jordan Cheeks

Reputation: 103

Playing a audio clip when my application starts.

I am new to android development, I have looked at tutorials on implementing the audio files into Eclipse in a raw file, but all the tutorials I have seen are for audio clips on click I need the audio to start automatically when the application loads up

Help Please

Upvotes: 0

Views: 145

Answers (2)

Sunny Kumar Aditya
Sunny Kumar Aditya

Reputation: 2846

Add your audio file in raw folder

in Oncreate

MediaPlayer mPlay = MediaPlayer.create(this, R.raw.youraudiofile);

    mPlay.start();

in on onPause

mplay.stop();

and in OnDestroy

           mPlay.stop();
        mPlay.release();
        mPlay = null ;

Upvotes: 0

Jean-Philippe Roy
Jean-Philippe Roy

Reputation: 4812

If you have a tutorial that shows you how to play an audio clip when you click a button. Simply pick up the code from the onClick() event showed in the tutorial and move it to the onCreate() event of your Activity you wish to play the clip.

It shouldn't be that hard, really.

Upvotes: 1

Related Questions