我正在尝试使用Kotlin在videoView中实现setOnErrorListener。

我在android开发者网站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?!
    })

09-28 00:01