diff --git a/README.md b/README.md index fd445187..ab9715d4 100644 --- a/README.md +++ b/README.md @@ -770,6 +770,12 @@ Platforms: Android ExoPlayer #### source Sets the media source. You can pass an asset loaded via require or an object with a uri. +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. + +Rendering the player component with a null source will init the player, and start playing once a source value is provided. + +Providing a null source value after loading a previous source will stop playback, and clear out the previous source content. + The docs for this prop are incomplete and will be updated as each option is investigated and tested. diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index d7c33214..fe95fdf4 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -465,6 +465,7 @@ class ReactExoplayerView extends FrameLayout implements player.prepare(mediaSource, !haveResumePosition, false); playerNeedsSource = false; + reLayout(exoPlayerView); eventEmitter.loadStart(); loadVideoStarted = true; } @@ -1012,7 +1013,6 @@ class ReactExoplayerView extends FrameLayout implements public void setSrc(final Uri uri, final String extension, Map headers) { if (uri != null) { - boolean isOriginalSourceNull = srcUri == null; boolean isSourceEqual = uri.equals(srcUri); this.srcUri = uri; @@ -1022,12 +1022,23 @@ class ReactExoplayerView extends FrameLayout implements DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, bandwidthMeter, this.requestHeaders); - if (!isOriginalSourceNull && !isSourceEqual) { + if (!isSourceEqual) { reloadSource(); } } } + public void clearSrc() { + if (srcUri != null) { + player.stop(true); + this.srcUri = null; + this.extension = null; + this.requestHeaders = null; + this.mediaDataSourceFactory = null; + clearResumePosition(); + } + } + public void setProgressUpdateInterval(final float progressUpdateInterval) { mProgressUpdateInterval = progressUpdateInterval; } @@ -1038,14 +1049,13 @@ class ReactExoplayerView extends FrameLayout implements public void setRawSrc(final Uri uri, final String extension) { if (uri != null) { - boolean isOriginalSourceNull = srcUri == null; boolean isSourceEqual = uri.equals(srcUri); this.srcUri = uri; this.extension = extension; this.mediaDataSourceFactory = buildDataSourceFactory(true); - if (!isOriginalSourceNull && !isSourceEqual) { + if (!isSourceEqual) { reloadSource(); } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 0d81e0b2..eccbee75 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -144,6 +144,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager headers = src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS)) : null; if (TextUtils.isEmpty(uriString)) { + videoView.clearSrc(); return; }