Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android exoplayer出错时如何跳过播放列表中的MP4视频_Android_Exoplayer - Fatal编程技术网

Android exoplayer出错时如何跳过播放列表中的MP4视频

Android exoplayer出错时如何跳过播放列表中的MP4视频,android,exoplayer,Android,Exoplayer,我使用ExoPlayer在Android中播放视频。我有3个本地mp4文件,想从这些文件创建播放列表。我正在使用ConcatenatingMediaSource将所有文件添加到一个播放列表中 override fun playFromList(list: List<VideoEntity>) { val userAgent = Util.getUserAgent(this, getString(R.string.app_name)) //2

我使用ExoPlayer在Android中播放视频。我有3个本地mp4文件,想从这些文件创建播放列表。我正在使用ConcatenatingMediaSource将所有文件添加到一个播放列表中

    override fun playFromList(list: List<VideoEntity>) {

        val userAgent = Util.getUserAgent(this, getString(R.string.app_name))
        //2
        val concatenatedSource = ConcatenatingMediaSource()

        list.forEach {

            if (it.localPath != null) {
                val dataSourceFactory = DefaultDataSourceFactory(this, userAgent)
                val extractorFactory = DefaultExtractorsFactory()

                val mediaSource = ProgressiveMediaSource
                        .Factory(dataSourceFactory, extractorFactory)
                        .createMediaSource(Uri.parse(it.localPath))

                concatenatedSource.addMediaSource(mediaSource)
            }

            exoPlayer.prepare(concatenatedSource)
        }

        exoPlayer.playWhenReady = true
        exoPlayerView.player = exoPlayer

    }
我的问题是,如何捕获该错误,以便跳过该文件并继续播放其他文件


谢谢

您需要将事件侦听器添加到exo player并在那里处理错误

fun onPlayerError(error: ExoPlaybackException) {
        when (error.type) {
            ExoPlaybackException.TYPE_SOURCE -> Log.e(TAG, "TYPE_SOURCE: " + error.sourceException.message)

            ExoPlaybackException.TYPE_RENDERER -> Log.e(TAG, "TYPE_RENDERER: " + error.rendererException.message)

            ExoPlaybackException.TYPE_UNEXPECTED -> Log.e(TAG, "TYPE_UNEXPECTED: " + error.unexpectedException.message)
        }
    }

嘿你找到播放列表的解决方案了吗?
fun onPlayerError(error: ExoPlaybackException) {
        when (error.type) {
            ExoPlaybackException.TYPE_SOURCE -> Log.e(TAG, "TYPE_SOURCE: " + error.sourceException.message)

            ExoPlaybackException.TYPE_RENDERER -> Log.e(TAG, "TYPE_RENDERER: " + error.rendererException.message)

            ExoPlaybackException.TYPE_UNEXPECTED -> Log.e(TAG, "TYPE_UNEXPECTED: " + error.unexpectedException.message)
        }
    }