【问题标题】:soundPool.load() inside (wait) Thread?soundPool.load() 内部(等待)线程?
【发布时间】:2013-04-29 01:48:23
【问题描述】:

嘿,我想在包含睡眠命令的线程内的 soundPool 上加载声音。我正在谈论的块看起来像这样:

Thread wait = new Thread() {
    @Override
    public void run() {
       try {

          sleep(800);
          soundsMap.put(SOUND5, soundPool.load(this, R.raw.w5, 1));

       } catch (InterruptedException e) {
          // blub
       } finally {

       }
    }
 };
 wait.start();

Eclipse 在load 标记一个错误并写道:

SoundPool 类型中的方法load(Context, int, int) 不适用于参数(new Thread(){}, int, int)

有人知道我该如何解决这个问题吗?我真的不明白消息想告诉我什么。

【问题讨论】:

    标签: android multithreading soundpool


    【解决方案1】:

    SoundPool.load() 的三参数形式将 Context 引用作为参数。 Activity 扩展了 Context,所以如果你在 Activity 子类中编写代码,你可以使用 this

    你没有这样做——你在一个通用的Thread实例中——编译器会让你知道。

    要解决此问题,您需要从 Runnable 类中引用您的 Activity 实例,并将其作为第一个参数传递给 load()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多