将文件添加到 MediaPlayer 很容易:
mp = MediaPlayer.create(Myctivity.this, R.raw.sound);
但是,如果我将文件名作为来自这样的函数的参数呢?
public void CreateSound(String filename, float volume)
{
mp = MediaPlayer.create(Myctivity.this, R.raw.???);
mp.setVolume(volume, volume);
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}