Skip to content

Commit

Permalink
Feat/add rtsp support (#3677)
Browse files Browse the repository at this point in the history
* feat(android) : add rtsp support
  • Loading branch information
freeboub authored Apr 16, 2024
1 parent 336b9f0 commit 2285eba
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ dependencies {
implementation "androidx.media3:media3-exoplayer-dash:$media3_version"
// For HLS playback support with ExoPlayer
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"

implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
// For ad insertion using the Interactive Media Ads SDK with ExoPlayer
if (useExoplayerIMA) {
implementation "androidx.media3:media3-exoplayer-ima:$media3_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static androidx.media3.common.C.CONTENT_TYPE_DASH;
import static androidx.media3.common.C.CONTENT_TYPE_HLS;
import static androidx.media3.common.C.CONTENT_TYPE_OTHER;
import static androidx.media3.common.C.CONTENT_TYPE_RTSP;
import static androidx.media3.common.C.CONTENT_TYPE_SS;
import static androidx.media3.common.C.TIME_END_OF_SOURCE;

Expand Down Expand Up @@ -68,6 +69,7 @@
import androidx.media3.exoplayer.ima.ImaAdsLoader;
import androidx.media3.exoplayer.mediacodec.MediaCodecInfo;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
import androidx.media3.exoplayer.rtsp.RtspMediaSource;
import androidx.media3.exoplayer.smoothstreaming.DefaultSsChunkSource;
import androidx.media3.exoplayer.smoothstreaming.SsMediaSource;
import androidx.media3.exoplayer.source.ClippingMediaSource;
Expand Down Expand Up @@ -792,8 +794,13 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessi
if (uri == null) {
throw new IllegalStateException("Invalid video uri");
}
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
: uri.getLastPathSegment());
int type;
if ("rtsp".equals(overrideExtension)) {
type = C.TYPE_RTSP;
} else {
type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
: uri.getLastPathSegment());
}
config.setDisableDisconnectError(this.disableDisconnectError);

MediaItem.Builder mediaItemBuilder = new MediaItem.Builder().setUri(uri);
Expand Down Expand Up @@ -836,6 +843,9 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessi
mediaDataSourceFactory
);
break;
case CONTENT_TYPE_RTSP:
mediaSourceFactory = new RtspMediaSource.Factory();
break;
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private boolean startsWithValidScheme(String uriString) {
|| lowerCaseUri.startsWith("https://")
|| lowerCaseUri.startsWith("content://")
|| lowerCaseUri.startsWith("file://")
|| lowerCaseUri.startsWith("rtsp://")
|| lowerCaseUri.startsWith("asset://");
}
}
12 changes: 12 additions & 0 deletions examples/basic/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ android {
configurations.all {
resolutionStrategy { force 'androidx.core:core:1.9.0' }
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude("META-INF/*.kotlin_module")
}
}


Expand Down
2 changes: 1 addition & 1 deletion examples/basic/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
5 changes: 5 additions & 0 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ class VideoPlayer extends Component {
'https://proxy.uat.widevine.com/proxy?provider=widevine_test',
},
},
{
description: 'rtsp big bug bunny',
uri: 'rtsp://rtspstream:[email protected]/movie',
type: 'rtsp',
}
];

// poster which can be displayed
Expand Down
2 changes: 1 addition & 1 deletion src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!uri) {
console.log('Trying to load empty source');
}
const isNetwork = !!(uri && uri.match(/^https?:/));
const isNetwork = !!(uri && uri.match(/^(rtp|rtsp|http|https):/));
const isAsset = !!(
uri &&
uri.match(
Expand Down

0 comments on commit 2285eba

Please sign in to comment.