2013-04-29 31 views
1

嘿,我想加載在其中包含睡眠指令線程內的Soundpool聲音。我說的是塊看起來像這樣:soundPool.load()裏面(等待)線程?

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(); 

蝕在load標誌着一個錯誤,並寫道:

的方法load(Context, int, int)在類型SoundPool不適用於參數(new Thread(){}, int, int)

有沒有人一個想法,我怎麼能解決這個問題?我真的不明白這封郵件想告訴我什麼。

回答

0

SoundPool.load()的三個參數的形式取Context參考作爲參數。 Activity延伸Context,所以如果你在一個Activity子類編寫代碼,你可以只使用this

你不這樣做 - 你在一個通用的Thread實例 - 和編譯器讓你知道。

要解決此問題,您需要引用Runnable類中的Activity實例,並將其作爲第一個參數傳遞給load()

+0

謝謝你,解決它:) – user2330482 2013-05-07 03:30:50