我有这样的结构:
1) 主要 Activity :
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(this, R.raw.mysound, 1);”它给我错误 - “SoundPool 类型中的方法 load(Context, int, int) 不适用于参数 (GameView, int, int)”。伙计们,我该如何解决?当我使用“扩展 Activity ”时它工作正常,但在 SurfaceView 中它不起作用。请帮忙。
最佳答案
更改您的代码以像这样传递上下文:
mySound = sp.load(context, R.raw.mysound, 1);
关于android - 如何在 SurfaceView 中使用 SoundPool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9247916/