VEX-5044: Allow exoplayer to preinit with empty source (#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
This commit is contained in:
parent
80873102a4
commit
cba88fa9d8
@ -770,6 +770,12 @@ Platforms: Android ExoPlayer
|
|||||||
#### source
|
#### source
|
||||||
Sets the media source. You can pass an asset loaded via require or an object with a uri.
|
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.
|
The docs for this prop are incomplete and will be updated as each option is investigated and tested.
|
||||||
|
|
||||||
|
|
||||||
|
@ -497,6 +497,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
player.prepare(mediaSource, !haveResumePosition, false);
|
player.prepare(mediaSource, !haveResumePosition, false);
|
||||||
playerNeedsSource = false;
|
playerNeedsSource = false;
|
||||||
|
|
||||||
|
reLayout(exoPlayerView);
|
||||||
eventEmitter.loadStart();
|
eventEmitter.loadStart();
|
||||||
loadVideoStarted = true;
|
loadVideoStarted = true;
|
||||||
}
|
}
|
||||||
@ -1045,7 +1046,6 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
public void setSrc(final Uri uri, final String extension, Map<String, String> headers) {
|
public void setSrc(final Uri uri, final String extension, Map<String, String> headers) {
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
boolean isOriginalSourceNull = srcUri == null;
|
|
||||||
boolean isSourceEqual = uri.equals(srcUri);
|
boolean isSourceEqual = uri.equals(srcUri);
|
||||||
|
|
||||||
this.srcUri = uri;
|
this.srcUri = uri;
|
||||||
@ -1055,12 +1055,23 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, bandwidthMeter,
|
DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext, bandwidthMeter,
|
||||||
this.requestHeaders);
|
this.requestHeaders);
|
||||||
|
|
||||||
if (!isOriginalSourceNull && !isSourceEqual) {
|
if (!isSourceEqual) {
|
||||||
reloadSource();
|
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) {
|
public void setProgressUpdateInterval(final float progressUpdateInterval) {
|
||||||
mProgressUpdateInterval = progressUpdateInterval;
|
mProgressUpdateInterval = progressUpdateInterval;
|
||||||
}
|
}
|
||||||
@ -1071,14 +1082,13 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
|
|
||||||
public void setRawSrc(final Uri uri, final String extension) {
|
public void setRawSrc(final Uri uri, final String extension) {
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
boolean isOriginalSourceNull = srcUri == null;
|
|
||||||
boolean isSourceEqual = uri.equals(srcUri);
|
boolean isSourceEqual = uri.equals(srcUri);
|
||||||
|
|
||||||
this.srcUri = uri;
|
this.srcUri = uri;
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.mediaDataSourceFactory = buildDataSourceFactory(true);
|
this.mediaDataSourceFactory = buildDataSourceFactory(true);
|
||||||
|
|
||||||
if (!isOriginalSourceNull && !isSourceEqual) {
|
if (!isSourceEqual) {
|
||||||
reloadSource();
|
reloadSource();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
|||||||
Map<String, String> headers = src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS)) : null;
|
Map<String, String> headers = src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS)) : null;
|
||||||
|
|
||||||
if (TextUtils.isEmpty(uriString)) {
|
if (TextUtils.isEmpty(uriString)) {
|
||||||
|
videoView.clearSrc();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user