VEX-6779: React Native Video buildDrmSessionManager crash followup (#24)

Fix infinite loading on some devices caused by earlier fix to drm session manager crash
This commit is contained in:
Armands Malejev 2022-04-07 19:36:50 +03:00 committed by GitHub
parent 4d17096630
commit f78c623df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,6 +510,7 @@ class ReactExoplayerView extends FrameLayout implements
private void initializePlayer() { private void initializePlayer() {
ReactExoplayerView self = this; ReactExoplayerView self = this;
Activity activity = themedReactContext.getCurrentActivity();
// This ensures all props have been settled, to avoid async racing conditions. // This ensures all props have been settled, to avoid async racing conditions.
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
@ -519,7 +520,6 @@ class ReactExoplayerView extends FrameLayout implements
// Initialize core configuration and listeners // Initialize core configuration and listeners
initializePlayerCore(self); initializePlayerCore(self);
} }
if (playerNeedsSource && srcUri != null) { if (playerNeedsSource && srcUri != null) {
exoPlayerView.invalidateAspectRatio(); exoPlayerView.invalidateAspectRatio();
// DRM session manager creation must be done on a different thread to prevent crashes so we start a new thread // DRM session manager creation must be done on a different thread to prevent crashes so we start a new thread
@ -529,14 +529,16 @@ class ReactExoplayerView extends FrameLayout implements
public void run() { public void run() {
// DRM initialization must run on a different thread // DRM initialization must run on a different thread
DrmSessionManager drmSessionManager = initializePlayerDrm(self); DrmSessionManager drmSessionManager = initializePlayerDrm(self);
if (drmSessionManager == null) { if (drmSessionManager == null && self.drmUUID != null) {
// Failed to intialize DRM session manager - cannot continue // Failed to intialize DRM session manager - cannot continue
Log.e("ExoPlayer Exception", "Failed to initialize DRM Session Manager Framework!");
eventEmitter.error("Failed to initialize DRM Session Manager Framework!", new Exception("DRM Session Manager Framework failure!"), "3003");
return; return;
} }
// Initialize handler to run on the main thread // Initialize handler to run on the main thread
new Handler(Looper.getMainLooper()).post(new Runnable () { activity.runOnUiThread(new Runnable() {
@Override public void run() {
public void run () {
// Source initialization must run on the main thread // Source initialization must run on the main thread
initializePlayerSource(self, drmSessionManager); initializePlayerSource(self, drmSessionManager);
} }
@ -595,6 +597,7 @@ class ReactExoplayerView extends FrameLayout implements
PlaybackParameters params = new PlaybackParameters(rate, 1f); PlaybackParameters params = new PlaybackParameters(rate, 1f);
player.setPlaybackParameters(params); player.setPlaybackParameters(params);
} }
private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) { private DrmSessionManager initializePlayerDrm(ReactExoplayerView self) {
@ -1283,6 +1286,14 @@ class ReactExoplayerView extends FrameLayout implements
} else if(cause instanceof MediaDrmCallbackException) { } else if(cause instanceof MediaDrmCallbackException) {
errorCode = "3005"; errorCode = "3005";
errorString = getResources().getString(R.string.unrecognized_media_format); errorString = getResources().getString(R.string.unrecognized_media_format);
if (!hasDrmFailed) {
// When DRM fails to reach the app level certificate server it will fail with a source error so we assume that it is DRM related and try one more time
hasDrmFailed = true;
playerNeedsSource = true;
updateResumePosition();
initializePlayer();
return;
}
} else { } else {
errorCode = "2021"; errorCode = "2021";
errorString = getResources().getString(R.string.unrecognized_media_format); errorString = getResources().getString(R.string.unrecognized_media_format);