Try to change your adapter
implementation like below:
(尝试如下更改您的adapter
实现:)
class SecondAdapter(val content:Array<String>) : RecyclerView.Adapter<SecondCustomViewGolder>(){
//var lessons = arrayOf("Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh",
// "Lapan", "Sembilan")
private var soundEngine = SoundEngine()
var soundList = arrayOf(R.raw.sound1, R.raw.sound2,R.raw.sound1, R.raw.sound2,
R.raw.sound1, R.raw.sound2,R.raw.sound1, R.raw.sound2,
R.raw.sound1)
override fun getItemCount(): Int {
return content.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.viewTwo.setOnClickListener {
val soundToPlay = soundEngine.load(holder.viewTwo.context, soundList.get(position), 1)
soundEngine.play(soundToPlay, 1F, 1F, 1, 0, 1F)
}
}
}
class SecondCustomViewGolder(var viewTwo : View) : RecyclerView.ViewHolder(viewTwo){
}
Also change your play
implementation in your SoundEngine
like below:
(也可以如下更改SoundEngine
play
实现:)
fun play(soundID: Int, leftVolume: Float, rightVolume: Float, priority: Int, loop: Int, rate: Float) {
soundPool.setOnLoadCompleteListener { soundPool, sampleId, _ ->
soundPool.play(sampleId, leftVolume, rightVolume, priority, loop, rate)
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…