我怎么能在SurfaceView使用的Soundpool?
问题描述:
我有这样的结构:我怎么能在SurfaceView使用的Soundpool?
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的方法负载(上下文,INT,INT)不适用于参数(GameView,INT,INT)”。伙计们,我该如何解决它?当我使用“扩展活动”它可以正常工作,但在SurfaceView中不起作用。请帮助。
答
更改您的代码通过上下文,像这样:
mySound = sp.load(context, R.raw.mysound, 1);