2015-11-04 67 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

非常感谢。 –