【问题标题】:How I can use SoundPool in SurfaceView?如何在 SurfaceView 中使用 SoundPool?
【发布时间】:2012-02-12 09:59:29
【问题描述】:

我有这个结构:

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(this, R.raw.mysound, 1);”它给了我错误-“SoundPool 类型中的方法 load(Context, int, int) 不适用于参数 (GameView, int, int)”。大佬们,怎么解决啊当我使用“扩展活动”时它工作正常,但在 SurfaceView 中它不起作用。请帮忙。

【问题讨论】:

    标签: android surfaceview soundpool


    【解决方案1】:

    更改您的代码以像这样传递上下文:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-10-10
      • 1970-01-01
      相关资源
      最近更新 更多