Chore(android): refactor drm props (#3846)
This commit is contained in:
parent
3a4a13011a
commit
cfb5b1cd31
66
android/src/main/java/com/brentvatne/common/api/DRMProps.kt
Normal file
66
android/src/main/java/com/brentvatne/common/api/DRMProps.kt
Normal file
@ -0,0 +1,66 @@
|
||||
package com.brentvatne.common.api
|
||||
|
||||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetArray
|
||||
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetString
|
||||
import com.facebook.react.bridge.ReadableMap
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Class representing DRM props for host.
|
||||
* Only generic code here, no reference to the player.
|
||||
*/
|
||||
class DRMProps {
|
||||
/**
|
||||
* string version of configured UUID for drm prop
|
||||
*/
|
||||
var drmType: String? = null
|
||||
|
||||
/**
|
||||
* Configured UUID for drm prop
|
||||
*/
|
||||
var drmUUID: UUID? = null
|
||||
|
||||
/**
|
||||
* DRM license server to be used
|
||||
*/
|
||||
var drmLicenseServer: String? = null
|
||||
|
||||
/**
|
||||
* DRM Http Header to access to license server
|
||||
*/
|
||||
var drmLicenseHeader: Array<String> = emptyArray<String>()
|
||||
companion object {
|
||||
private const val PROP_DRM_TYPE = "type"
|
||||
private const val PROP_DRM_LICENSE_SERVER = "licenseServer"
|
||||
private const val PROP_DRM_HEADERS = "headers"
|
||||
private const val PROP_DRM_HEADERS_KEY = "key"
|
||||
private const val PROP_DRM_HEADERS_VALUE = "value"
|
||||
|
||||
/** parse the source ReadableMap received from app */
|
||||
@JvmStatic
|
||||
fun parse(src: ReadableMap?): DRMProps? {
|
||||
var drm: DRMProps? = null
|
||||
if (src != null && src.hasKey(PROP_DRM_TYPE)) {
|
||||
drm = DRMProps()
|
||||
drm.drmType = safeGetString(src, PROP_DRM_TYPE)
|
||||
drm.drmLicenseServer = safeGetString(src, PROP_DRM_LICENSE_SERVER)
|
||||
val drmHeadersArray = safeGetArray(src, PROP_DRM_HEADERS)
|
||||
if (drm.drmType != null && drm.drmLicenseServer != null) {
|
||||
if (drmHeadersArray != null) {
|
||||
val drmKeyRequestPropertiesList = ArrayList<String?>()
|
||||
for (i in 0 until drmHeadersArray.size()) {
|
||||
val current = drmHeadersArray.getMap(i)
|
||||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_KEY))
|
||||
drmKeyRequestPropertiesList.add(safeGetString(current, PROP_DRM_HEADERS_VALUE))
|
||||
}
|
||||
val array = emptyArray<String>()
|
||||
drm.drmLicenseHeader = drmKeyRequestPropertiesList.toArray(array)
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return drm
|
||||
}
|
||||
}
|
||||
}
|
@ -110,6 +110,7 @@ import androidx.media3.ui.LegacyPlayerControlView;
|
||||
import com.brentvatne.common.api.BufferConfig;
|
||||
import com.brentvatne.common.api.BufferingStrategy;
|
||||
import com.brentvatne.common.api.ControlsConfig;
|
||||
import com.brentvatne.common.api.DRMProps;
|
||||
import com.brentvatne.common.api.ResizeMode;
|
||||
import com.brentvatne.common.api.SideLoadedTextTrack;
|
||||
import com.brentvatne.common.api.SideLoadedTextTrackList;
|
||||
@ -238,9 +239,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
private float mProgressUpdateInterval = 250.0f;
|
||||
private boolean playInBackground = false;
|
||||
private boolean mReportBandwidth = false;
|
||||
private UUID drmUUID = null;
|
||||
private String drmLicenseUrl = null;
|
||||
private String[] drmLicenseHeader = null;
|
||||
private DRMProps drmProps;
|
||||
private boolean controls;
|
||||
private Uri adTagUrl;
|
||||
|
||||
@ -774,10 +773,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) {
|
||||
DrmSessionManager drmSessionManager = null;
|
||||
if (self.drmUUID != null) {
|
||||
if (self.drmProps != null) {
|
||||
try {
|
||||
drmSessionManager = self.buildDrmSessionManager(self.drmUUID, self.drmLicenseUrl,
|
||||
self.drmLicenseHeader);
|
||||
drmSessionManager = self.buildDrmSessionManager(self.drmProps.getDrmUUID(),
|
||||
self.drmProps.getDrmLicenseServer(),
|
||||
self.drmProps.getDrmLicenseHeader());
|
||||
} catch (UnsupportedDrmException e) {
|
||||
int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
|
||||
: (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
|
||||
@ -794,7 +794,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
return;
|
||||
}
|
||||
DrmSessionManager drmSessionManager = initializePlayerDrm(this);
|
||||
if (drmSessionManager == null && drmUUID != null) {
|
||||
if (drmSessionManager == null && drmProps != null && drmProps.getDrmUUID() != null) {
|
||||
// Failed to intialize DRM session manager - cannot continue
|
||||
DebugLog.e(TAG, "Failed to initialize DRM Session Manager Framework!");
|
||||
eventEmitter.error("Failed to initialize DRM Session Manager Framework!", new Exception("DRM Session Manager Framework failure!"), "3003");
|
||||
@ -2229,7 +2229,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
public void setUseTextureView(boolean useTextureView) {
|
||||
boolean finallyUseTextureView = useTextureView && this.drmUUID == null;
|
||||
boolean finallyUseTextureView = useTextureView && drmProps == null;
|
||||
exoPlayerView.setUseTextureView(finallyUseTextureView);
|
||||
}
|
||||
|
||||
@ -2256,16 +2256,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
initializePlayer();
|
||||
}
|
||||
|
||||
public void setDrmType(UUID drmType) {
|
||||
this.drmUUID = drmType;
|
||||
}
|
||||
|
||||
public void setDrmLicenseUrl(String licenseUrl){
|
||||
this.drmLicenseUrl = licenseUrl;
|
||||
}
|
||||
|
||||
public void setDrmLicenseHeader(String[] header){
|
||||
this.drmLicenseHeader = header;
|
||||
public void setDrm(DRMProps drmProps) {
|
||||
this.drmProps = drmProps;
|
||||
if (drmProps != null && drmProps.getDrmType() != null) {
|
||||
this.drmProps.setDrmUUID(Util.getDrmUuid(drmProps.getDrmType()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,6 +12,7 @@ import androidx.media3.common.util.Util;
|
||||
import com.brentvatne.common.api.BufferConfig;
|
||||
import com.brentvatne.common.api.BufferingStrategy;
|
||||
import com.brentvatne.common.api.ControlsConfig;
|
||||
import com.brentvatne.common.api.DRMProps;
|
||||
import com.brentvatne.common.api.ResizeMode;
|
||||
import com.brentvatne.common.api.SideLoadedTextTrackList;
|
||||
import com.brentvatne.common.api.Source;
|
||||
@ -39,9 +40,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
private static final String PROP_SRC = "src";
|
||||
private static final String PROP_AD_TAG_URL = "adTagUrl";
|
||||
private static final String PROP_DRM = "drm";
|
||||
private static final String PROP_DRM_TYPE = "type";
|
||||
private static final String PROP_DRM_LICENSE_SERVER = "licenseServer";
|
||||
private static final String PROP_DRM_HEADERS = "headers";
|
||||
private static final String PROP_SRC_HEADERS = "requestHeaders";
|
||||
private static final String PROP_RESIZE_MODE = "resizeMode";
|
||||
private static final String PROP_REPEAT = "repeat";
|
||||
private static final String PROP_SELECTED_AUDIO_TRACK = "selectedAudioTrack";
|
||||
@ -117,28 +116,9 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
|
||||
@ReactProp(name = PROP_DRM)
|
||||
public void setDRM(final ReactExoplayerView videoView, @Nullable ReadableMap drm) {
|
||||
if (drm != null && drm.hasKey(PROP_DRM_TYPE)) {
|
||||
String drmType = ReactBridgeUtils.safeGetString(drm, PROP_DRM_TYPE);
|
||||
String drmLicenseServer = ReactBridgeUtils.safeGetString(drm, PROP_DRM_LICENSE_SERVER);
|
||||
ReadableArray drmHeadersArray = ReactBridgeUtils.safeGetArray(drm, PROP_DRM_HEADERS);
|
||||
if (drmType != null && drmLicenseServer != null && Util.getDrmUuid(drmType) != null) {
|
||||
UUID drmUUID = Util.getDrmUuid(drmType);
|
||||
videoView.setDrmType(drmUUID);
|
||||
videoView.setDrmLicenseUrl(drmLicenseServer);
|
||||
if (drmHeadersArray != null) {
|
||||
ArrayList<String> drmKeyRequestPropertiesList = new ArrayList<>();
|
||||
for (int i = 0; i < drmHeadersArray.size(); i++) {
|
||||
ReadableMap current = drmHeadersArray.getMap(i);
|
||||
String key = current.hasKey("key") ? current.getString("key") : null;
|
||||
String value = current.hasKey("value") ? current.getString("value") : null;
|
||||
drmKeyRequestPropertiesList.add(key);
|
||||
drmKeyRequestPropertiesList.add(value);
|
||||
}
|
||||
videoView.setDrmLicenseHeader(drmKeyRequestPropertiesList.toArray(new String[0]));
|
||||
}
|
||||
videoView.setUseTextureView(false);
|
||||
}
|
||||
}
|
||||
DRMProps drmProps = DRMProps.parse(drm);
|
||||
videoView.setDrm(drmProps);
|
||||
videoView.setUseTextureView(false);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_SRC)
|
||||
|
Loading…
Reference in New Issue
Block a user