Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use UdpDataSource in exoplayer? #2029

Closed
SwaranSK opened this issue Nov 3, 2016 · 12 comments
Closed

How to use UdpDataSource in exoplayer? #2029

SwaranSK opened this issue Nov 3, 2016 · 12 comments
Labels

Comments

@SwaranSK
Copy link

SwaranSK commented Nov 3, 2016

I 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.

@tresvecesseis
Copy link
Contributor

tresvecesseis commented Nov 4, 2016

Have you checked if your device supports multicast?, lots of devices don´t support multicast at all and some only for ipv6, for us, the most reliable way to test for multicast support is to check the presence of the “/proc/net/igmp” file.

@SwaranSK
Copy link
Author

SwaranSK commented Nov 4, 2016

@tresvecesseis Yes, my device support multicast for ipv4 and ipv6 both. igmp and igmp6 files are there in the said directory. UDP stream is working fine on VLC Player from the same device. But I want to use ExoPlayer. Please check my code also whether I am doing right or not. If it is not the right way please guide me for corrections.

@ojw28 ojw28 added the question label Nov 6, 2016
@SwaranSK
Copy link
Author

Is there anyone who can help regarding the issue?

@Avetri
Copy link

Avetri commented Nov 18, 2016

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

@SwaranSK
Copy link
Author

@Avetri,Thanks for helping. Uni-casting is working fine with these modifications. But unable to multicast as it is throwing socket timeout exception. Looking forward for any lead to solve the issue.

@boulaycote
Copy link

I could not get ExoPlayer2 to work with UDP/MPEG-TS. ExoPlayer1 (r1.5.12) works though. Which is where ExtractorSampleSource is.

@SwaranSK
Copy link
Author

SwaranSK commented Nov 28, 2016

@boulaycote, it will work but for uni-casting only. Just make the changes as suggested by @Avetri. And use ExtactorMediaSource instead of HlsMediaSource.

@fredEallen
Copy link

@SidneySeldon where can I find ExtactorMediaSource?

@SwaranSK
Copy link
Author

@eminallen In my project its at below path. But its not fixed. It depends on your project directory structure. ExoPlayer/library/src/main/java/com/google/android/exoplayer2/source/ExtractorMediaSource.java

@msuman26
Copy link

@Avetri is your patch available in any of the Exoplayer releases? I was trying to use UdpDataSource class that defines Multicast socket. But not sure how to create a instance of UDPDataSource

@Avetri
Copy link

Avetri commented May 12, 2017

@msuman26 I am not sure. I have not commited it into the repo.

@google google locked and limited conversation to collaborators Jun 28, 2017
@tonihei
Copy link
Collaborator

tonihei commented Jun 17, 2019

UdpDataSource will be supported out-of-the-box in our next release, similar to the solution proposed in #2029 (comment).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants