Reputation: 4267
I created a simple application. In my main activity class i use this to play a sound when a button is clicked
MediaPlayer buttonSound = MediaPlayer.create(this, R.drawable.button_sound);
public void onClick(View arg0){
buttonSound.start();
}
In my main activity class i have a service that start a background music
Intent svc=new Intent(this, BackgroundSoundService.class);
startService(svc);
the problem is that if i dont' start the service startService(svc);
the button sound don't play!
Why? They are two differents things!
Upvotes: 1
Views: 689
Reputation: 11951
Create a raw folder in /res/raw
and store your audio or sound file in this folder. from this folder call your audio file.
like this
MediaPlayer soundBtn = MediaPlayer.create(this, R.raw.sound_btn);
Upvotes: 0
Reputation: 132972
here
MediaPlayer buttonSound = MediaPlayer.create(this, R.drawable.button_sound);
//^^^^^^^
don't put your audio or video files in drawable folder . move it to res/raw folder and Create media instance as:
MediaPlayer buttonSound = MediaPlayer.create(this, R.raw.button_sound);
Upvotes: 1