Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -17,6 +17,7 @@ def configStringPath = (
|
||||
).md5()
|
||||
|
||||
android {
|
||||
namespace 'com.brentvatne.react'
|
||||
compileSdkVersion safeExtGet('compileSdkVersion', 31)
|
||||
buildToolsVersion safeExtGet('buildToolsVersion', '30.0.2')
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import static com.google.android.exoplayer2.C.CONTENT_TYPE_DASH;
|
||||
import static com.google.android.exoplayer2.C.CONTENT_TYPE_HLS;
|
||||
import static com.google.android.exoplayer2.C.CONTENT_TYPE_OTHER;
|
||||
import static com.google.android.exoplayer2.C.CONTENT_TYPE_SS;
|
||||
import static com.google.android.exoplayer2.C.TIME_END_OF_SOURCE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
@@ -94,6 +95,7 @@ import com.google.android.exoplayer2.source.dash.manifest.Representation;
|
||||
import com.google.android.exoplayer2.ext.ima.ImaAdsLoader;
|
||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
||||
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
|
||||
import com.google.android.exoplayer2.source.ClippingMediaSource;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.net.CookieHandler;
|
||||
@@ -210,6 +212,8 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
// Props from React
|
||||
private int backBufferDurationMs = DefaultLoadControl.DEFAULT_BACK_BUFFER_DURATION_MS;
|
||||
private Uri srcUri;
|
||||
private long startTimeMs = -1;
|
||||
private long endTimeMs = -1;
|
||||
private String extension;
|
||||
private boolean repeat;
|
||||
private String audioTrackType;
|
||||
@@ -717,7 +721,8 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager drmSessionManager) {
|
||||
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
||||
MediaSource videoSource = buildMediaSource(self.srcUri, self.extension, drmSessionManager);
|
||||
MediaSource videoSource = buildMediaSource(self.srcUri, self.extension, drmSessionManager, startTimeMs,
|
||||
endTimeMs);
|
||||
MediaSource mediaSourceWithAds = null;
|
||||
if (adTagUrl != null) {
|
||||
MediaSource.Factory mediaSourceFactory = new DefaultMediaSourceFactory(mediaDataSourceFactory)
|
||||
@@ -815,7 +820,8 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
}
|
||||
|
||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) {
|
||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager,
|
||||
long startTimeMs, long endTimeMs) {
|
||||
if (uri == null) {
|
||||
throw new IllegalStateException("Invalid video uri");
|
||||
}
|
||||
@@ -831,7 +837,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
MediaItem mediaItem = mediaItemBuilder.build();
|
||||
|
||||
MediaSource mediaSource = null;
|
||||
DrmSessionManagerProvider drmProvider = null;
|
||||
if (drmSessionManager != null) {
|
||||
drmProvider = new DrmSessionManagerProvider() {
|
||||
@@ -845,35 +851,49 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
switch (type) {
|
||||
case CONTENT_TYPE_SS:
|
||||
return new SsMediaSource.Factory(
|
||||
mediaSource = new SsMediaSource.Factory(
|
||||
new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
|
||||
buildDataSourceFactory(false)).setDrmSessionManagerProvider(drmProvider)
|
||||
.setLoadErrorHandlingPolicy(
|
||||
config.buildLoadErrorHandlingPolicy(minLoadRetryCount))
|
||||
.createMediaSource(mediaItem);
|
||||
break;
|
||||
case CONTENT_TYPE_DASH:
|
||||
return new DashMediaSource.Factory(
|
||||
mediaSource = new DashMediaSource.Factory(
|
||||
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
|
||||
buildDataSourceFactory(false)).setDrmSessionManagerProvider(drmProvider)
|
||||
.setLoadErrorHandlingPolicy(
|
||||
config.buildLoadErrorHandlingPolicy(minLoadRetryCount))
|
||||
.createMediaSource(mediaItem);
|
||||
break;
|
||||
case CONTENT_TYPE_HLS:
|
||||
return new HlsMediaSource.Factory(
|
||||
mediaSource = new HlsMediaSource.Factory(
|
||||
mediaDataSourceFactory).setDrmSessionManagerProvider(drmProvider)
|
||||
.setLoadErrorHandlingPolicy(
|
||||
config.buildLoadErrorHandlingPolicy(minLoadRetryCount))
|
||||
.createMediaSource(mediaItem);
|
||||
break;
|
||||
case CONTENT_TYPE_OTHER:
|
||||
return new ProgressiveMediaSource.Factory(
|
||||
mediaSource = new ProgressiveMediaSource.Factory(
|
||||
mediaDataSourceFactory).setDrmSessionManagerProvider(drmProvider)
|
||||
.setLoadErrorHandlingPolicy(
|
||||
config.buildLoadErrorHandlingPolicy(minLoadRetryCount))
|
||||
.createMediaSource(mediaItem);
|
||||
break;
|
||||
default: {
|
||||
throw new IllegalStateException("Unsupported type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
if (startTimeMs >= 0 && endTimeMs >= 0) {
|
||||
return new ClippingMediaSource(mediaSource, startTimeMs * 1000, endTimeMs * 1000);
|
||||
} else if (startTimeMs >= 0) {
|
||||
return new ClippingMediaSource(mediaSource, startTimeMs * 1000, TIME_END_OF_SOURCE);
|
||||
} else if (endTimeMs >= 0) {
|
||||
return new ClippingMediaSource(mediaSource, 0, endTimeMs * 1000);
|
||||
}
|
||||
|
||||
return mediaSource;
|
||||
}
|
||||
|
||||
private ArrayList<MediaSource> buildTextSources() {
|
||||
@@ -1530,11 +1550,15 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
// ReactExoplayerViewManager public api
|
||||
|
||||
public void setSrc(final Uri uri, final String extension, Map<String, String> headers) {
|
||||
public void setSrc(final Uri uri, final long startTimeMs, final long endTimeMs, final String extension,
|
||||
Map<String, String> headers) {
|
||||
if (uri != null) {
|
||||
boolean isSourceEqual = uri.equals(srcUri);
|
||||
boolean isSourceEqual = uri.equals(srcUri) && startTimeMs == this.startTimeMs
|
||||
&& endTimeMs == this.endTimeMs;
|
||||
hasDrmFailed = false;
|
||||
this.srcUri = uri;
|
||||
this.startTimeMs = startTimeMs;
|
||||
this.endTimeMs = endTimeMs;
|
||||
this.extension = extension;
|
||||
this.requestHeaders = headers;
|
||||
this.mediaDataSourceFactory = DataSourceUtil.getDefaultDataSourceFactory(this.themedReactContext,
|
||||
@@ -1552,6 +1576,8 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
player.stop();
|
||||
player.clearMediaItems();
|
||||
this.srcUri = null;
|
||||
this.startTimeMs = -1;
|
||||
this.endTimeMs = -1;
|
||||
this.extension = null;
|
||||
this.requestHeaders = null;
|
||||
this.mediaDataSourceFactory = null;
|
||||
|
@@ -28,9 +28,10 @@ import javax.annotation.Nullable;
|
||||
public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerView> {
|
||||
|
||||
private static final String REACT_CLASS = "RCTVideo";
|
||||
|
||||
private static final String PROP_SRC = "src";
|
||||
private static final String PROP_SRC_URI = "uri";
|
||||
private static final String PROP_SRC_START_TIME = "startTime";
|
||||
private static final String PROP_SRC_END_TIME = "endTime";
|
||||
private static final String PROP_AD_TAG_URL = "adTagUrl";
|
||||
private static final String PROP_SRC_TYPE = "type";
|
||||
private static final String PROP_DRM = "drm";
|
||||
@@ -152,6 +153,8 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
public void setSrc(final ReactExoplayerView videoView, @Nullable ReadableMap src) {
|
||||
Context context = videoView.getContext().getApplicationContext();
|
||||
String uriString = src.hasKey(PROP_SRC_URI) ? src.getString(PROP_SRC_URI) : null;
|
||||
int startTimeMs = src.hasKey(PROP_SRC_START_TIME) ? src.getInt(PROP_SRC_START_TIME) : -1;
|
||||
int endTimeMs = src.hasKey(PROP_SRC_END_TIME) ? src.getInt(PROP_SRC_END_TIME) : -1;
|
||||
String extension = src.hasKey(PROP_SRC_TYPE) ? src.getString(PROP_SRC_TYPE) : null;
|
||||
Map<String, String> headers = src.hasKey(PROP_SRC_HEADERS) ? toStringMap(src.getMap(PROP_SRC_HEADERS)) : null;
|
||||
|
||||
@@ -164,7 +167,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
Uri srcUri = Uri.parse(uriString);
|
||||
|
||||
if (srcUri != null) {
|
||||
videoView.setSrc(srcUri, extension, headers);
|
||||
videoView.setSrc(srcUri, startTimeMs, endTimeMs, extension, headers);
|
||||
}
|
||||
} else {
|
||||
int identifier = context.getResources().getIdentifier(
|
||||
|
@@ -14,27 +14,27 @@
|
||||
android:paddingTop="4dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton android:id="@id/exo_prev"
|
||||
<ImageButton android:id="@+id/exo_prev"
|
||||
style="@style/ExoMediaButton.Previous"/>
|
||||
|
||||
<ImageButton android:id="@id/exo_rew"
|
||||
<ImageButton android:id="@+id/exo_rew"
|
||||
style="@style/ExoMediaButton.Rewind"/>
|
||||
<FrameLayout
|
||||
android:id="@+id/exo_play_pause_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center">
|
||||
<ImageButton android:id="@id/exo_play"
|
||||
<ImageButton android:id="@+id/exo_play"
|
||||
style="@style/ExoMediaButton.Play"/>
|
||||
|
||||
<ImageButton android:id="@id/exo_pause"
|
||||
<ImageButton android:id="@+id/exo_pause"
|
||||
style="@style/ExoMediaButton.Pause"/>
|
||||
</FrameLayout>
|
||||
|
||||
<ImageButton android:id="@id/exo_ffwd"
|
||||
<ImageButton android:id="@+id/exo_ffwd"
|
||||
style="@style/ExoMediaButton.FastForward"/>
|
||||
|
||||
<ImageButton android:id="@id/exo_next"
|
||||
<ImageButton android:id="@+id/exo_next"
|
||||
style="@style/ExoMediaButton.Next"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -46,7 +46,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView android:id="@id/exo_position"
|
||||
<TextView android:id="@+id/exo_position"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
@@ -57,12 +57,12 @@
|
||||
android:textColor="#FFBEBEBE"/>
|
||||
|
||||
<com.google.android.exoplayer2.ui.DefaultTimeBar
|
||||
android:id="@id/exo_progress"
|
||||
android:id="@+id/exo_progress"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="26dp"/>
|
||||
|
||||
<TextView android:id="@id/exo_duration"
|
||||
<TextView android:id="@+id/exo_duration"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
@@ -73,7 +73,7 @@
|
||||
android:textColor="#FFBEBEBE"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@id/exo_fullscreen"
|
||||
android:id="@+id/exo_fullscreen"
|
||||
style="@style/ExoMediaButton.FullScreen"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
|
Reference in New Issue
Block a user