2012-02-12 22 views
1

私はこの構造を有する:SoundViewをSurfaceViewでどのように使用できますか?

1)主な活動:ラインで

public class mainActivity extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState);  
    setContentView(new GameView(this)); 

} 

2)ゲーム・ビュー

SoundPool sp; 
int mySound = 0;  

public class GameView extends SurfaceView implements SurfaceHolder.Callback { 


public GameView(Context context) { 
    super(context); 

    sp = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); 
    mySound = sp.load(this, R.raw.mysound, 1);  

} 

「mySound = sp.load(この、R.raw.mysound 、1); "それは私にエラーを与えます - "SoundPool型のメソッドload(Context、int、int)は引数(GameView、int、int)には適用されません"。みんな、どうすれば修正できますか?私は "extend activities"を使うとうまくいきますが、SurfaceViewでは動作しません。助けてください。

答えて

3

そうのようなコンテキストを渡すようにコードを変更します。

mySound = sp.load(context, R.raw.mysound, 1);