Is it possible to have parameters of a method in android to be the value for R.raw.parametervalue, for example;
public void sound(SOMETHING sound){
m = MediaPlayer.create(getApplicationContext(), R.raw.sound);
}
Is it possible to have parameters of a method in android to be the value for R.raw.parametervalue, for example;
public void sound(SOMETHING sound){
m = MediaPlayer.create(getApplicationContext(), R.raw.sound);
}
yes it is possible, as R.raw.sound is an int. So your method signature will have
(Context context, Int soundID)
For sound is not getting recognized, you need to create sound file in 'raw' folder, this problem is mentioned here - Check this one out
use it:
public void sound(int soundResource){
m = MediaPlayer.create(getApplicationContext(), soundResource);
}
You can pass the id and retrieve raw file from resources using id.
Example:
public void sound (int soundId) {
AssetFileDescriptor aFileDesc = context.getResources().openRawResourceFd(soundId);
m = MediaPlayer.create(getApplicationContext(), soundId);
//do something
}
Hope this helps.