[英]SoundPool plays sound only the first time, when it is called
我需要在Kotlin
使用soundPool
,我编写了如下代码:
private fun playThatSound(sound: String) {
var soundPool: SoundPool? = null
var soundId: Int = 0
soundPool = SoundPool(6, AudioManager.STREAM_MUSIC, 0)
when(sound) {
"boo" -> {
soundPool.load(baseContext, R.raw.boo, 1)
soundId = R.raw.boo
}
}
soundPool.play(soundId, 1F, 1F, 0, 0, 1F)
}
我这样称呼它:
playThatSound("boo")
声音仅在我第一次调用时播放,然后我必须清除模拟器数据或在重新安装应用程序之前关闭并重新打开我的三星 A50。
boo.mp3 文件是 213Ko 我缺少什么? 任何想法最受欢迎。
实际上,soundPool 需要一些时间来加载声音。 所以我需要使用
onLoadComplete(soundPool: SoundPool?, sampleId: Int, status: Int) {
// let us know that a sound has been loaded by the SoundPool
Toast.makeText(this, "Sound $numSoundsLoaded Loaded",Toast.LENGTH_SHORT).show()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.