Exoplayer无法播放一些音频流

时间:2017-04-26 21:21:33

标签: android audio exoplayer m3u8 vitamio

我开发了一些Android应用程序来收听互联网广播电台。

对于音频流,我一直在使用Vitamio库。不幸的是,它不再受支持,并且包含与Android 7的兼容性问题。

经过多次尝试,我决定去ExoPlayer库。我对易用性和不断更新非常满意。另外,它减少了我的APK的大小三次。

不幸的是,ExoPlayer库无法播放某些音频流。我尝试过调试,更改对URL的调用等等。不成功。

这些是我无法使用ExoPlayer库播放的流的示例,但我可以使用Vitamio重现:

http://42747t.lp.azioncdn.net:1935/2747t/a/mp4:access_options/rtmp-live/atl_poa.sdp/playlist.m3u8 http://192747t.lp.azioncdn.net/2747t/a/mp4:access_options/rtmp-live/gau_centro.sdp/playlist.m3u8

其中一些流对我的应用程序成功非常重要。

我无法访问服务器。

这是logcat上的内容:

  

04-26 21:09:20.189 27953-27953 / com.eneasgesing.radios.rs E / EventLogger:playerFailed [987.08]                                                                           com.google.android.exoplayer2.ExoPlaybackException                                                                               在com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:345)                                                                               在android.os.Handler.dispatchMessage(Handler.java:98)                                                                               在android.os.Looper.loop(Looper.java:154)                                                                               在android.os.HandlerThread.run(HandlerThread.java:61)                                                                               在com.google.android.exoplayer2.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40)                                                                            com.google.android.exoplayer2.source.UnrecognizedInputFormatException:由此造成的可提取(MatroskaExtractor,FragmentedMp4Extractor,Mp4Extractor,Mp3Extractor,AdtsExtractor,Ac3Extractor,TsExtractor,FlvExtractor,OggExtractor,PsExtractor,WavExtractor)可以读取流的无。                                                                               在com.google.android.exoplayer2.source.ExtractorMediaPeriod $ ExtractorHolder.selectExtractor(ExtractorMediaPeriod.java:713)                                                                               在com.google.android.exoplayer2.source.ExtractorMediaPeriod $ ExtractingLoadable.load(ExtractorMediaPeriod.java:636)                                                                               在com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:295)                                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                               at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)                                                                               在java.lang.Thread.run(Thread.java:761)

2 个答案:

答案 0 :(得分:2)

查看您用于启动exoplayer的部分代码可能有所帮助,我假设您使用的是标准ExtractorMediaSource

.m3u8个文件实际上是播放列表,文本文件,链接到媒体文件 - 通常用于直播。您需要其他MediaSource,尝试 HLS ,或HlsMediaSource代替ExtractorMediaSource

HLS代表HTTP Live Streaming。

答案 1 :(得分:0)

要播放.m3u8文件,请在初始化Exoplayer时使用以下代码:

    Handler mHandler = new Handler();

    String userAgent = Util.getUserAgent(context, "Your Application Name");

    DataSource.Factory dataSourceFactory = new DefaultHttpDataSourceFactory(
                    userAgent, null,
                    DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
                    1800000,
                    true);

    HlsMediaSource mediaSource = new HlsMediaSource(Uri.parse(mediaUrl),dataSourceFactory, 1800000,mHandler, null);

    if (mediaUrl != null) {
        videoPlayer.prepare(mediaSource);
        videoPlayer.setPlayWhenReady(true);
    }