Android:如何将R.raw ...作为常规参数添加到方法中?

时间:2017-03-01 09:18:20

标签: android android-mediaplayer

我正在尝试创建一种方法,在不同的活动中播放一些声音。

     Route::resource('/details','DetailController');

什么类型应该有"声音"参数?

2 个答案:

答案 0 :(得分:2)

传递资源值可以是integers,如下所示:

public void playSound(View view, @RawRes int sound){
    mpSound = MediaPlayer.create(this, sound);
    mpSound.start();
}

调用您的方法将是:

playSound(mView, R.raw.sound);

答案 1 :(得分:0)

它应该是带有@RawRes Annotation的int类型,如下所示:

public void playSound(View view, @RawRes int sound){
    mpSound = MediaPlayer.create(this, sound);
    mpSound.start();
}


如果您没有传递原始资源,您将看到此错误:

Expected resource of type raw