Reputation: 393
I am trying to create a method, to play some sound in different activities.
public void playSound(View view, ??? sound){
mpSound = MediaPlayer.create(this, R.raw.sound);
mpSound.start();
}
What type should have a "sound" parameter?
Upvotes: 0
Views: 855
Reputation: 5381
Passing resource values can be integers
like this:
public void playSound(View view, @RawRes int sound){
mpSound = MediaPlayer.create(this, sound);
mpSound.start();
}
Calling your method would be:
playSound(mView, R.raw.sound);
Upvotes: 4
Reputation: 1262
It should be a int type with @RawRes Annotation like this:
public void playSound(View view, @RawRes int sound){
mpSound = MediaPlayer.create(this, sound);
mpSound.start();
}
You will see this error if you don't pass a raw resource:
Expected resource of type raw
Upvotes: 1