2013-11-26 32 views
1

我有一個關於按鈕聲音的問題。即使我在「res」文件夾(res/raw)中創建文件夾,我也無法使用「raw」。 Eclipse問我是否想在R文件中創建....是否方便?請幫忙。任何幫助將是一個驚喜。Android MediaPlayer中的原始問題

這個想法是,當我點擊一個ImageButton聲音的圖像的顏色。

MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1); 
    public void dos(View v) { 
    TextView f = (TextView) findViewById(R.id.pts); 
    TextView t = (TextView) findViewById(R.id.color); 
    c++; 
    if (t.getText().toString().equals("YELLOW")) { 
     Toast.makeText(this, "Correct", Toast.LENGTH_SHORT).show(); 
     pts++; 
     color(v); 
     mp1.start(); 
     f.setText(Integer.toString(pts)); 
    } else { 
     Toast.makeText(this, "Fail", Toast.LENGTH_SHORT) 
       .show(); 

    } 
} 

唯一的問題是在這條線

MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1); 

原料被強調,並表示,需要建立在R檔的字段或常量。

+0

你輸入正確的資源類?它應該是類似於 .R – ranjk89

+0

是的,真的很確定 – user3010527

回答

0

嘗試改變這一點:

MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1); 

有了這個:

`final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);` 
+0

不工作.... 謝謝 – user3010527