I have this code:
package com.example.pr;
import android.media.MediaPlayer;
public class Audio{
MediaPlayer mp;
public void playClick(){
mp = MediaPlayer.create(Audio.this, R.raw.click);
mp.start();
}
}
I have an error in “create” with this message “The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (Audio, int)”
why?
MediaPlayer.create() needs a Context as first parameter. Pass in the current Activity and it should work.
try:
in your Activity:
but don’t forget to call release on the MediaPlayer instance once the sound has finished, or you’ll get an exception.
However, for playing short clicks using a SoundPool might be better anyway.