简体   繁体   English

Exoplayer for android,尝试流式传输 m3u8 文件并出现错误:没有可用的提取器可以读取流

[英]Exoplayer for android, trying to stream a m3u8 file and getting error: None of the available extractors could read the stream

I am trying to stream an m3u8 file and I am getting an error.我正在尝试流式传输 m3u8 文件,但出现错误。 The url I am using is the following: http://storage.googleapis.com/videos.siku.org/10005/dash/master.m3u8 This streaming video does work in a browser.我使用的 url 如下: http://storage.googleapis.com/videos.siku.org/10005/dash/master.m3u8这个流媒体视频在浏览器中工作。 I am getting the following error at runtime:我在运行时收到以下错误:

ExoPlayerImplInternal: Source error. ExoPlayerImplInternal:源错误。 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. com.google.android.exoplayer2.source.UnrecognizedInputFormatException:没有可用的提取器(MatroskaExtractor、FragmentedMp4Extractor、Mp4Extractor、Mp3Extractor、AdtsExtractor、Ac3Extractor、TsExtractor、FlvExtractor、OggExtractor、PsExtractor、WavExtractor、AmrExtractor、Ac4Extractor、FlacExtractor)可以读取流. 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)在 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)

I am using the class ExoPlayerHelper (which was taken from a stackoverflow question, although I did implement this the recommended way and I was getting the same error)我正在使用ExoPlayerHelper类(取自 stackoverflow 问题,尽管我确实按照推荐的方式实现了这个并且我得到了同样的错误)

Here is the class I am using:这是我正在使用的课程:

class ExoPlayerHelper(
    private val playerView: PlayerView,
    onError: (ExoPlaybackException) -> Unit,
    onPlayerBuffer: (Boolean) -> Unit
) {
    private var exoPlayer: ExoPlayer? = null
    private var mediaSource: ProgressiveMediaSource? = null
    private val playerListener = object : Player.EventListener {
        override fun onPlayerError(error: ExoPlaybackException) {
            super.onPlayerError(error)
            onError(error)
        }

        override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
            super.onPlayerStateChanged(playWhenReady, playbackState)
            onPlayerBuffer(playbackState == Player.STATE_BUFFERING)
        }
    }

    fun initializePlayer(url: String) {
        exoPlayer = SimpleExoPlayer.Builder(playerView.context).build()
        exoPlayer!!.repeatMode = Player.REPEAT_MODE_ALL
        exoPlayer!!.addListener(playerListener)
        playerView.player = exoPlayer

        val userAgent =
            Util.getUserAgent(playerView.context, playerView.context.getString(R.string.app_name))
        mediaSource = ProgressiveMediaSource
            .Factory(
                DefaultDataSourceFactory(playerView.context, userAgent),
                DefaultExtractorsFactory()
            )
            .createMediaSource(Uri.parse(url))
            exoPlayer!!.prepare(mediaSource!!, true, false)
            exoPlayer!!.playWhenReady = true
        }
    }
}

I do get a blank com.google.android.exoplayer2.ui.PlayerView with the controls appearing.我确实得到了一个空白的 com.google.android.exoplayer2.ui.PlayerView 并显示了控件。 When pressing the play button I get the same error message:按下播放按钮时,我收到相同的错误消息:

com.google.android.exoplayer2.ExoPlaybackException: 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. com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: 没有可用的提取器(MatroskaExtractor、FragmentedMp4Extractor、Mp4Extractor、Mp3Extractor、AdtsExtractor、Ac3Extractor、TsExtractor、FlvExtractor、OggExtractor、PsExtractor、WavExtractor、 AmrExtractor、Ac4Extractor、FlacExtractor)可以读取流。

Any clues as to why I am getting this error UnrecognizedInputFormatException?关于为什么我收到此错误 UnrecognizedInputFormatException 的任何线索?

Since you are trying to play m3u8 file, you need to create HLS media source.由于您正在尝试播放 m3u8 文件,因此您需要创建 HLS 媒体源。 So just make this below change -所以只需在下面进行更改 -

mediaSource =HlsMediaSource.Factory(DefaultHttpDataSourceFactory(userAgent))
                .createMediaSource(uri)

Use This method you have to use HlsMediaSource使用 这个方法你必须使用 HlsMediaSource

 Uri uri = Uri.parse(urlStream);
 //MediaSource mediaSource = buildMediaSource(uri);
 DataSource.Factory dataSourceFactory =
         new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "app-name"));
 HlsMediaSource hlsMediaSource =
         new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
 player = ExoPlayerFactory.newSimpleInstance(this);
 player.setPlayWhenReady(playWhenReady);
 player.seekTo(currentWindow, playbackPosition);

 // Create a player instance.

 // Prepare the player with the media source.
 //player.prepare(mediaSource);
 player.prepare(hlsMediaSource, false, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM