我正在尝试使用 Kotlin 在 videoView 中实现 setOnErrorListener
。我在安卓开发者网站中找到了这个 https://developer.android.com/reference/android/media/MediaPlayer.OnErrorListener.html
我卡在这里:
vv!!.setOnErrorListener(MediaPlayer.OnErrorListener {
mediaPlayer, i, i2 -> true
// how to restart the player here?!
})
完整代码:
mediacontroller = MediaController(this)
mediacontroller!!.setAnchorView(vv)
val uriPath = "" //update package name
uri = Uri.parse(uriPath)
vv!!.setMediaController(mediacontroller)
vv!!.setVideoURI(uri)
vv!!.requestFocus()
vv!!.start()
vv!!.setOnCompletionListener {
}
vv!!.setOnPreparedListener {
}
vv!!.setOnErrorListener(MediaPlayer.OnErrorListener {
mediaPlayer, i, i2 -> true
})
你离得很近
vv!!.setOnErrorListener(MediaPlayer.OnErrorListener {
mediaPlayer, i, i2 ->
// mediaPlayer is refer to your MediaPlayer instance.
//You should restart it in here.
true
// how to restart the player here?!
})
我自己找到了:
vv!!.setOnErrorListener(MediaPlayer.OnErrorListener {
mediaPlayer, i, i2 ->
vv!!.start()
true
})