RecyclerView
单击行时,我没有播放任何声音。声音单据正在我的SecondAdapter
. 这SecondAdapter
是我的RecyclerView
Activity 类的适配器类。当Logcat
我单击行时反映了这一点:
2019-12-01 18:57:21.340 24162-24162/com.shamuraq.svgintent6 W/SoundPool: sample 1 not READY
2019-12-01 18:57:21.371 24162-24162/com.shamuraq.svgintent6 W/SoundPool: sample 1 not READY
2019-12-01 18:57:21.392 24162-24256/com.shamuraq.svgintent6 I/OMXClient: IOmx service obtained
2019-12-01 18:57:21.431 24162-24162/com.shamuraq.svgintent6 W/SoundPool: sample 1 not READY
2019-12-01 18:57:21.465 24162-24162/com.shamuraq.svgintent6 W/SoundPool: sample 1 not READY
2019-12-01 18:57:21.497 24162-24162/com.shamuraq.svgintent6 W/SoundPool: sample 1 not READY
2019-12-01 18:57:21.497 24162-24263/com.shamuraq.svgintent6 I/OMXClient: IOmx service obtained
2019-12-01 18:57:21.515 24162-24264/com.shamuraq.svgintent6 I/OMXClient: IOmx service obtained
2019-12-01 18:57:21.569 24162-24271/com.shamuraq.svgintent6 I/OMXClient: IOmx service obtained
2019-12-01 18:57:21.580 24162-24274/com.shamuraq.svgintent6 I/OMXClient: IOmx service obtained
可能是什么问题?
适配器类:
class SecondAdapter(val content:Array<String>) : RecyclerView.Adapter<SecondCustomViewGolder>(){
//var lessons = arrayOf("Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh",
// "Lapan", "Sembilan")
var soundList = arrayOf(R.raw.ahem_x,R.raw.bad_disk_x,R.raw.baseball_hit,R.raw.bloop_x,R.raw.blurp_x)
override fun getItemCount(): Int {
return soundList.size
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SecondCustomViewGolder {
var layoutInflater = LayoutInflater.from(parent.context)
var cellForRow = layoutInflater.inflate(R.layout.lesson_row, parent, false)
return SecondCustomViewGolder(cellForRow)
}
override fun onBindViewHolder(holder: SecondCustomViewGolder, position: Int) {
holder.loadAndPlaySound(soundList.get(position), 1)
}
}
class SecondCustomViewGolder(var viewTwo : View) : RecyclerView.ViewHolder(viewTwo) {
private var soundEngine = SoundEngine()
fun loadAndPlaySound(soundIdToPlay:Int, priority: Int) {
val soundToPlay = soundEngine.load(viewTwo.context, soundIdToPlay, priority)
soundEngine.play(soundToPlay, 1F, 1F, 1, 0, 1F)
}
}