当我执行并播放媒体播放器的音频到最后时,不会触发setOnCompletionListener
。
您能告诉我我还需要设置什么吗?
mediaPlayer = MediaPlayer()
val audioBuilder = AudioAttributes.Builder()
audioBuilder.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
audioBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC)
audioBuilder.setUsage(AudioAttributes.USAGE_MEDIA)
showLoading()
val attribute : AudioAttributes = audioBuilder.build()
mediaPlayer!!.setAudioAttributes(attribute )
mediaPlayer!!.setOnErrorListener { mp, what, extra ->
mp.reset();
Log.i("SYSTEM", "mp: ${mp}\nwhat: ${what}\nextra: $extra")
false
}
mediaPlayer!!.setOnCompletionListener {
Toast.makeText(this,"end",Toast.LENGTH_SHORT).show()
}
mediaPlayer!!.setOnPreparedListener {
hideLoading()
mediaPlayer!!.start()
}