How to use UdpDataSource in exoplayer?
See original GitHub issueI tried in the way given below, but unable to open udp stream in exoplayer. Second which media source should we use for UdpDataSource, i.e., DASH, HLS, SS and Regular Media. Currently I am using SImpleExoPlayerView. Is it ok to use this view for UDP and RTMP? Should I take SurfaceView or any other view? It will be great help if someone can guide me and share the code for playing UDP and RTMP stream in ExoPlayer. I am new to exo player.
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.simpleExoPlayerView);
simpleExoPlayerView.setPlayer(player);
DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
UdpDataSource.Factory udpDataSource = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "MainActivity"), defaultBandwidthMeter);
Uri uri = Uri.parse("udp://@239.18.36.42:4300");
MediaSource udpMedia = new HlsMediaSource(uri, udpDataSource, null, null);
player.prepare(udpMedia);
player.setPlayWhenReady(playWhenReady);
Currently I am using r2.0.3 library. Iam sending UDP stream using ffmpeg from another machine. I am getting no error. In some issues comments, I read that ExtractorSimpleSource can be used for playing UDP stream but it is not available in current version. Very keen to know the solution. Please Guide.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
UdpDataSource (ExoPlayer library)
Opens the source to read the specified data. If an IOException is thrown, callers must still call DataSource.close() to ensure that any partial...
Read more >Playing UDP, RTP stream using Exoplayer2 | by Jatin Mishra
Step 1: Add INTERNET permission in the manifest file. ; Step 2: Add exoplayer 2 dependencies in your app's build.gradle file. ; Step...
Read more >Android Exoplayer 2 UDP Decoding issue - Stack Overflow
I Know Udpstreaming is not officialy supported by ExoPlayer but the UdpDataSource class seems to work well. After all the test , i...
Read more >How to use UdpDataSource in exoplayer? - Bountysource
Second which media source should we use for UdpDataSource, i.e., ... me and share the code for playing UDP and RTMP stream in...
Read more >com.google.android.exoplayer2.upstream.UdpDataSource ...
... snippets using com.google.android.exoplayer2.upstream.UdpDataSource$UdpDataSourceException (Showing top 3 results out of 315). origin: google/ExoPlayer ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This diff turns on the supporting of UDP urls.
library/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSource.java index ae6f1e0..28a5b3d 100644 @@ -40,7 +40,9 @@ public final class DefaultDataSource implements DataSource { private static final String SCHEME_ASSET = "asset"; private static final String SCHEME_CONTENT = "content"; + private static final String SCHEME_UDP = "udp"; + private final DataSource udpDataSource; private final DataSource baseDataSource; private final DataSource fileDataSource; private final DataSource assetDataSource; @@ -99,6 +101,7 @@ public final class DefaultDataSource implements DataSource { this.fileDataSource = new FileDataSource(listener); this.assetDataSource = new AssetDataSource(context, listener); this.contentDataSource = new ContentDataSource(context, listener); + this.udpDataSource = new UdpDataSource(listener); } @Override @@ -116,6 +119,8 @@ public final class DefaultDataSource implements DataSource { dataSource = assetDataSource; } else if (SCHEME_CONTENT.equals(scheme)) { dataSource = contentDataSource; + } else if (SCHEME_UDP.equals(scheme)) { + dataSource = udpDataSource; } else { dataSource = baseDataSource; }UdpDataSource will be supported out-of-the-box in our next release, similar to the solution proposed in https://github.com/google/ExoPlayer/issues/2029#issuecomment-261480961.