Skip to content

Commit cba88fa

Browse files
authored
VEX-5044: Allow exoplayer to preinit with empty source (24i#6)
- Allow player to be init before source is provided, and later update once a source is provided. - Adds handling for providing a empty source in order to stop playback and clear out any existing content
1 parent 8087310 commit cba88fa

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,12 @@ Platforms: Android ExoPlayer
770770
#### source
771771
Sets the media source. You can pass an asset loaded via require or an object with a uri.
772772

773+
Setting the source will trigger the player to attempt to load the provided media with all other given props. Please be sure that all props are provided before/at the same time as setting the source.
774+
775+
Rendering the player component with a null source will init the player, and start playing once a source value is provided.
776+
777+
Providing a null source value after loading a previous source will stop playback, and clear out the previous source content.
778+
773779
The docs for this prop are incomplete and will be updated as each option is investigated and tested.
774780

775781

android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ public void run() {
497497
player.prepare(mediaSource, !haveResumePosition, false);
498498
playerNeedsSource = false;
499499

500+
reLayout(exoPlayerView);
500501
eventEmitter.loadStart();
501502
loadVideoStarted = true;
502503
}
@@ -1045,7 +1046,6 @@ public void onMetadata(Metadata metadata) {
10451046

10461047
public void setSrc(final Uri uri, final String extension, Map<String, String> headers) {
10471048
if (uri != null) {
1048-
boolean isOriginalSourceNull = srcUri == null;
10491049
boolean isSourceEqual = uri.equals(srcUri);
10501050

10511051
this.srcUri = uri;
@@ -1055,12 +1055,23 @@ public void setSrc(final Uri uri, final String extension, Map<String, String> he
10551055
DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, bandwidthMeter,
10561056
this.requestHeaders);
10571057

1058-
if (!isOriginalSourceNull && !isSourceEqual) {
1058+
if (!isSourceEqual) {
10591059
reloadSource();
10601060
}
10611061
}
10621062
}
10631063

1064+
public void clearSrc() {
1065+
if (srcUri != null) {
1066+
player.stop(true);
1067+
this.srcUri = null;
1068+
this.extension = null;
1069+
this.requestHeaders = null;
1070+
this.mediaDataSourceFactory = null;
1071+
clearResumePosition();
1072+
}
1073+
}
1074+
10641075
public void setProgressUpdateInterval(final float progressUpdateInterval) {
10651076
mProgressUpdateInterval = progressUpdateInterval;
10661077
}
@@ -1071,14 +1082,13 @@ public void setReportBandwidth(boolean reportBandwidth) {
10711082

10721083
public void setRawSrc(final Uri uri, final String extension) {
10731084
if (uri != null) {
1074-
boolean isOriginalSourceNull = srcUri == null;
10751085
boolean isSourceEqual = uri.equals(srcUri);
10761086

10771087
this.srcUri = uri;
10781088
this.extension = extension;
10791089
this.mediaDataSourceFactory = buildDataSourceFactory(true);
10801090

1081-
if (!isOriginalSourceNull && !isSourceEqual) {
1091+
if (!isSourceEqual) {
10821092
reloadSource();
10831093
}
10841094
}

android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public void setSrc(final ReactExoplayerView videoView, @Nullable ReadableMap src
147147
Map<String, String> headers = src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS)) : null;
148148

149149
if (TextUtils.isEmpty(uriString)) {
150+
videoView.clearSrc();
150151
return;
151152
}
152153

0 commit comments

Comments
 (0)