Recyclerview中的Exoplayer错误,源错误没有可用的提取器 [英] Exoplayer error in Recyclerview, Source error None of the available extractors

查看:391
本文介绍了Recyclerview中的Exoplayer错误,源错误没有可用的提取器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ExoPlayer在RecyclerView中流式传输视频.

I am using ExoPlayer to stream videos in a RecyclerView.

我正在ViewHolder的RecyclerView Adapter的bind方法中实现ExoPlayer.

I am implementing the ExoPlayer inside my RecyclerView Adapter's bind method inside my ViewHolder.

我正在使用的视频格式是m3u8,我正在使用的URL在浏览器中有效.所以我知道视频链接是有效的.我也在其中测试了一个youtube链接.

The video format I am using is m3u8 and the URL I am using works in a browser. So I know that the video link is valid. I've also testing a youtube link in there.

这是Recyclerview适配器的ViewHolder->

Here is the code from the Recyclerview adapter's ViewHolder ->

class ViewHolder private constructor(val binding: FeedRowBinding) :
    RecyclerView.ViewHolder(binding.root) {

    fun bind(context: Activity){
        if (entity.content.videolink != null) {
            setupVideoPlayer(entity.content.videolink, context)
        }
    }
}

private fun setupVideoPlayer(url: String, context: Activity) {
    val videoExoPlayer = SimpleExoPlayer.Builder(binding.videoView.context).build()
    videoExoPlayer.prepare(createUrlMediaSource(url, context))

    binding.play.setOnClickListener {
        videoExoPlayer.playWhenReady = true
    }

    binding.pause.setOnClickListener {
        videoExoPlayer.playWhenReady = false
    }
}

private fun createUrlMediaSource(url: String, context: Activity): MediaSource {
    val userAgent = Util.getUserAgent(context, context.getString(R.string.about))
    return ProgressiveMediaSource
           .Factory(DefaultDataSourceFactory(context, userAgent), DefaultExtractorsFactory())
           .createMediaSource(Uri.parse(url))
}

加载我的recyclerview并转到视频所在的行时,出现以下错误:

When loading my recyclerview and get to the row with the video I get the following error:

ExoPlayerImplInternal:源错误.com.google.android.exoplayer2.source.UnrecognizedInputFormatException:没有可用的提取器(MatroskaExtractor,FragmentedMp4Extractor,Mp4Extractor,Mp3Extractor,AdtsExtractor,Ac3Extractor,TsExtractor,FlvExtractor,OggExtractor,PsExtractor,WavExtractor,AmrExtractor,Ac4Extractor,FlacExtractor)可以读取流.在com.google.android.exoplayer2.source.ProgressiveMediaPeriod $ ExtractorHolder.selectExtractor(ProgressiveMediaPeriod.java:1090)在com.google.android.exoplayer2.source.ProgressiveMediaPeriod $ ExtractingLoadable.load(ProgressiveMediaPeriod.java:969)在com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:391)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:636)在java.lang.Thread.run(Thread.java:764)

ExoPlayerImplInternal: Source error. com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor, Ac4Extractor, FlacExtractor) could read the stream. at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractorHolder.selectExtractor(ProgressiveMediaPeriod.java:1090) at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:969) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764)

我不确定我在做什么错,关于如何解决此问题的任何想法?

I'm not sure what am I doing wrong, any ideas on how to fix this issue?

推荐答案

您需要修改 createUrlMediaSource

private fun createUrlMediaSource(url: String, context: Activity): MediaSource {
    val userAgent = Util.getUserAgent(context, context.getString(R.string.about))
    return ProgressiveMediaSource
           .Factory(DefaultDataSourceFactory(context, userAgent), DefaultExtractorsFactory())
           .createMediaSource(Uri.parse(url))
}

https://exoplayer.dev

  • DashMediaSource (用于DASH).
  • SsMediaSource 用于SmoothStreaming.
  • HlsMediaSource for HLS(这是您的格式=> .m3u8).
  • ProgressiveMediaSource (用于常规媒体文件).
  • DashMediaSource for DASH.
  • SsMediaSource for SmoothStreaming.
  • HlsMediaSource for HLS (this is your format => .m3u8).
  • ProgressiveMediaSource for regular media files.

因此,您需要将函数替换为此:

So you need to replace your function to this:

private fun createUrlMediaSource(url: String, context: Activity): MediaSource {
    val userAgent = Util.getUserAgent(context, context.getString(R.string.about))
    return HlsMediaSource
           .Factory(DefaultDataSourceFactory(context, userAgent), DefaultExtractorsFactory())
           .createMediaSource(Uri.parse(url))
}

这篇关于Recyclerview中的Exoplayer错误,源错误没有可用的提取器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆