UDP流不在ExoPlayer上播放

时间:2018-04-03 16:41:00

标签: java android udp exoplayer

我是Exoplayer udp流媒体的新手。我已经完成了一些关于HTTP直播但不是udp的工作。现在尝试在exoplayer上播放一个udp流,google了很多,但没有运气。

请查看以下logcat。

任何帮助都将不胜感激。

04-03 21:33:45.376 31547-31827/com.chernowii.udp_stream_android E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to udp://@x.x.x.x:xxxx
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:194)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:137)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:692)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:315)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
     Caused by: java.net.MalformedURLException: unknown protocol: udp
        at java.net.URL.<init>(URL.java:596)
        at java.net.URL.<init>(URL.java:486)
        at java.net.URL.<init>(URL.java:435)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:341)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:192)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:137) 
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:692) 
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:315) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:762) 
04-03 21:33:45.377 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerError...
04-03 21:33:45.378 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onTimelineChanged...
    Listener-onLoadingChanged...isLoading:false
04-03 21:33:45.379 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerStateChanged...1
04-03 21:33:45.395 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerStateChanged...2
04-03 21:33:45.396 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onTimelineChanged...
    Listener-onLoadingChanged...isLoading:true
04-03 21:33:48.406 31547-31827/com.chernowii.udp_stream_android E/ExoPlayerImplInternal: Source error.
    com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to udp://@224.2.2.1:3000
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:194)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:137)
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:692)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:315)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
     Caused by: java.net.MalformedURLException: unknown protocol: udp
        at java.net.URL.<init>(URL.java:596)
        at java.net.URL.<init>(URL.java:486)
        at java.net.URL.<init>(URL.java:435)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:341)
        at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:192)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:137) 
        at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:692) 
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:315) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:762) 
04-03 21:33:48.419 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerError...
04-03 21:33:48.421 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onTimelineChanged...
04-03 21:33:48.422 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onLoadingChanged...isLoading:false
04-03 21:33:48.423 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerStateChanged...1
04-03 21:33:48.440 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onPlayerStateChanged...2
04-03 21:33:48.441 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onTimelineChanged...
04-03 21:33:48.442 31547-31547/com.chernowii.udp_stream_android V/ExoPlayer GP Demo: Listener-onLoadingChanged...isLoading:true

2 个答案:

答案 0 :(得分:0)

您需要像

一样为Exo创建完全媒体源。
val myDataSourceFactory = DefaultDataSourceFactory(this, null, { -> UdpDataSource(this, 2000, 20000) })
// Extractor factory & media source
val extractorsFactory = DefaultExtractorsFactory()
val mediaSource = ExtractorMediaSource(uri, myDataSourceFactory, extractorsFactory, null, null)
player?.prepare(mediaSource, true, false)

答案 1 :(得分:0)

即使使用以下代码,我也有同样的问题:

aExtractorMediaSourceFactory := TJExtractorMediaSource_Factory.JavaClass.init(fDataSourceFactory);
aVideoSource := aExtractorMediaSourceFactory.createMediaSource(StrToJURI(aDataSource));
aExtractorMediaSourceFactory := nil;

似乎总是使用HTTP源类,而不是默认数据源。