在Google VR for Android示例中播放m3u8

时间:2016-06-09 18:32:15

标签: android virtual-reality exoplayer

我试图在来自Google https://developers.google.com/vr/android/samples/vrview的VRVideoView示例中播放m3u8网址。它与mp4或flv配合得很好,但在尝试使用m3u8时出现以下错误:

  

com.google.vr.sdk.samples.simplevideowidget E / VrVideoPlayerInternal:   136877483.onPlayerError                                                                                                       com.google.android.exoplayer.ExoPlaybackException:   com.google.android.exoplayer.extractor.ExtractorSampleSource $ UnrecognizedInputFormatException:   没有可用的提取器(WebmExtractor,   FragmentedMp4Extractor,Mp4Extractor,Mp3Extractor,AdtsExtractor,   TsExtractor,FlvExtractor,OggExtractor,PsExtractor,WavExtractor)   可以读取流。                                                                                                           在   com.google.android.exoplayer.SampleSourceTrackRenderer.maybeThrowError(SampleSourceTrackRenderer.java:263)                                                                                                           在   com.google.android.exoplayer.SampleSourceTrackRenderer.maybeThrowError(SampleSourceTrackRenderer.java:149)                                                                                                           在   com.google.android.exoplayer.ExoPlayerImplInternal.incrementalPrepareInternal(ExoPlayerImplInternal.java:275)                                                                                                           在   com.google.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:205)                                                                                                           在android.os.Handler.dispatchMessage(Handler.java:98)                                                                                                           在android.os.Looper.loop(Looper.java:154)                                                                                                           在android.os.HandlerThread.run(HandlerThread.java:61)                                                                                                           在   com.google.android.exoplayer.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40)

     

引起:   com.google.android.exoplayer.extractor.ExtractorSampleSource $ UnrecognizedInputFormatException:   没有可用的提取器(WebmExtractor,   FragmentedMp4Extractor,Mp4Extractor,Mp3Extractor,AdtsExtractor,   TsExtractor,FlvExtractor,OggExtractor,PsExtractor,WavExtractor)   可以读取流。                                                                                                           在   com.google.android.exoplayer.extractor.ExtractorSampleSource $ ExtractorHolder.selectExtractor(ExtractorSampleSource.java:899)                                                                                                           在   com.google.android.exoplayer.extractor.ExtractorSampleSource $ ExtractingLoadable.load(ExtractorSampleSource.java:829)                                                                                                           在   com.google.android.exoplayer.upstream.Loader $ LoadTask.run(Loader.java:209)                                                                                                           在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:428)                                                                                                           在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                                                           在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)                                                                                                           在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:607)                                                                                                           在java.lang.Thread.run(Thread.java:761)

我可以在这个错误堆栈中看到Exoplayer用于播放视频,但它不应该与m3u8一起使用吗?以下是我使用的网址:http://www.nacentapps.com/m3u8/index.m3u8

感谢您的帮助!

3 个答案:

答案 0 :(得分:1)

要播放m3u8,您需要做的就是将选项输入格式更改为,

'Uri uri = Uri.parse("https:proper_url.m3u8");
VrVideoView.Options vrVideoView = new VrVideoView.Options(); 
vrVideoView.inputFormat = VrVideoView.Options.FORMAT_HLS; 
videoWidgetView.loadVideo(uri, vrVideoView)'

答案 1 :(得分:0)

尝试使用下面的代码示例中的示例网址替换url,如果有效,则可以重用下面提供的github帐户中的示例代码: https://github.com/google/ExoPlayer/tree/master/demo/src/main/java/com/google/android/exoplayer

如果它不起作用,那么该文件必须有一些问题或exoplayer不支持它..

答案 2 :(得分:0)

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

Handler mHandler = new Handler();

String userAgent = Util.getUserAgent(context, "Exo Player");

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);
}