From 28ee05f657c2051f6128fb0e35c859431570a5fd Mon Sep 17 00:00:00 2001 From: arodriguez Date: Fri, 14 Jun 2019 08:24:31 +0200 Subject: [PATCH] Support for UDP data source --- .../exoplayer2/upstream/DefaultDataSource.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSource.java index bfc9a378441..aeaa977b120 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultDataSource.java @@ -55,6 +55,7 @@ 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_RTMP = "rtmp"; + private static final String SCHEME_UDP = "udp"; private static final String SCHEME_RAW = RawResourceDataSource.RAW_RESOURCE_SCHEME; private final Context context; @@ -66,6 +67,7 @@ public final class DefaultDataSource implements DataSource { @Nullable private DataSource assetDataSource; @Nullable private DataSource contentDataSource; @Nullable private DataSource rtmpDataSource; + @Nullable private DataSource udpDataSource; @Nullable private DataSource dataSchemeDataSource; @Nullable private DataSource rawResourceDataSource; @@ -139,6 +141,7 @@ public void addTransferListener(TransferListener transferListener) { maybeAddListenerToDataSource(assetDataSource, transferListener); maybeAddListenerToDataSource(contentDataSource, transferListener); maybeAddListenerToDataSource(rtmpDataSource, transferListener); + maybeAddListenerToDataSource(udpDataSource, transferListener); maybeAddListenerToDataSource(dataSchemeDataSource, transferListener); maybeAddListenerToDataSource(rawResourceDataSource, transferListener); } @@ -161,6 +164,8 @@ public long open(DataSpec dataSpec) throws IOException { dataSource = getContentDataSource(); } else if (SCHEME_RTMP.equals(scheme)) { dataSource = getRtmpDataSource(); + } else if(SCHEME_UDP.equals(scheme)){ + dataSource = getUdpDataSource(); } else if (DataSchemeDataSource.SCHEME_DATA.equals(scheme)) { dataSource = getDataSchemeDataSource(); } else if (SCHEME_RAW.equals(scheme)) { @@ -199,6 +204,14 @@ public void close() throws IOException { } } + private DataSource getUdpDataSource(){ + if (udpDataSource == null) { + udpDataSource = new UdpDataSource(); + addListenersToDataSource(udpDataSource); + } + return udpDataSource; + } + private DataSource getFileDataSource() { if (fileDataSource == null) { fileDataSource = new FileDataSource();