2016-10-21 33 views
0

我的應用程序中有一個按鈕,用於調用異步任務。 這個異步任務應該在每個ProgressUpdate上播放音頻文件。 我想通了很多,到目前爲止,但我堅持這一點:SoundPool.load問題上下文

我打電話

 this.strengthSound[0] = this.soundPool.load(this, R.raw.strength0,1); 
     this.strengthSound[1] = this.soundPool.load(this, R.raw.strength1,1); 
     this.strengthSound[2] = this.soundPool.load(this, R.raw.strength2,1); 
     this.strengthSound[3] = this.soundPool.load(this, R.raw.strength3,1); 
     this.strengthSound[4] = this.soundPool.load(this, R.raw.strength4,1); 

,以填補該strengthx.mp3秒的陣列。

反正:我得到一個錯誤「這個」負載聲明:

Error:(165, 57) error: incompatible types: AIM_start.start_AIM cannot be converted to Context 

什麼情況下做我有這個soundPool.load(背景下,資源ID,..)來使用?

感謝提前的幫助... :)

回答

1
private Context mContext; 

onCreate(...) { 
    mContext = this; 
} 


// inside your AsyncTask 
... 

    onProgressUpdate(int progress) { 
     this.strengthSound[0] = this.soundPool.load(mContext, R.raw.strength0,1); 
     ... 
    } 

我忘了AsyncTasks實際方法簽名,但這是基本的破敗。你錯用了this

this在你的活動和this在你的AsyncTask是不同的。 AsyncTask中的this引用自身,它是AsyncTask,但onCreate中的this引用(再次)本身,這是Activity本身。

不知道這是否有幫助,但隨時闡述評論:)

+0

這聽起來很像解決方案;我會讓你知道它是否工作... –