Android exoplayer出错时如何跳过播放列表中的MP4视频
我使用ExoPlayer在Android中播放视频。我有3个本地mp4文件,想从这些文件创建播放列表。我正在使用ConcatenatingMediaSource将所有文件添加到一个播放列表中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
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)
}
}