2015-11-04 69 views
0

我有擴展視圖的這個類,我想在下面的方法中添加一個聲音。通常我用下面的方法添加按鈕聲音。這堂課是一個可繪製的畫布,它給我看了一條紅線,但沒有跡象表明我需要改變。那麼我如何在下面的方法中添加聲音?我在不同的活動中呼籲我的觀點。提前致謝。在畫布類中添加聲音

if(checkCorrect == goal) { 
    MediaPlayer mediaPlayer = MediaPlayer.create(DrawGame.this,R.raw.button); 
       mediaPlayer.start(); 
       score += 10; 
       newGoal = true; 
       } 
+0

是DrawGame活動? –

+0

不,這是一個班,我會打電話給另一項活動。 –

+0

所以這是你的問題。 DrawGame必須是上下文類型「create(Context context,Uri uri)」 –

回答

0
class GameActivity extends Activity { 

    DrawGame game = new DrawGame(); 
    game.setContext(this); 



} 


class DrawGame { 
     Context context; 
    public void setContext(Context context) { 
     this.context = context; 
    } 

    if(checkCorrect == goal) { 
      MediaPlayer mediaPlayer = MediaPlayer.create(context,R.raw.button); 
      mediaPlayer.start(); 
      score += 10; 
      newGoal = true; 
      } 

    } 
+0

非常感謝。 –