Move DRM init to a separate thread
This commit is contained in:
parent
b6f3652636
commit
88f32ae3c8
@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -547,10 +548,46 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
PlaybackParameters params = new PlaybackParameters(rate, 1f);
|
PlaybackParameters params = new PlaybackParameters(rate, 1f);
|
||||||
player.setPlaybackParameters(params);
|
player.setPlaybackParameters(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
ExecutorService es = Executors.newSingleThreadExecutor();
|
||||||
|
es.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
// DRM
|
// DRM initialization must run on a different thread
|
||||||
|
initializePlayerDrm();
|
||||||
|
|
||||||
|
// Initialize handler to run on the main thread
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable () {
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
// Source initialization must run on the main thread
|
||||||
|
initializePlayerSource();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
finishPlayerInitialization();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
self.playerNeedsSource = true;
|
||||||
|
Log.e("ExoPlayer Exception", "Failed to initialize Player!");
|
||||||
|
Log.e("ExoPlayer Exception", ex.toString());
|
||||||
|
eventEmitter.error(ex.toString(), ex, "1001");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializePlayerDrm() {
|
||||||
DrmSessionManager drmSessionManager = null;
|
DrmSessionManager drmSessionManager = null;
|
||||||
if (self.drmUUID != null) {
|
if (self.drmUUID != null) {
|
||||||
try {
|
try {
|
||||||
@ -568,8 +605,9 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
// DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method
|
// DRM Session Manager failed to instantiate, no other work can be done - error has been handled by the instantiating method
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// End DRM
|
}
|
||||||
|
|
||||||
|
private void initializePlayerSource() {
|
||||||
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
||||||
MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager);
|
MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager);
|
||||||
MediaSource mediaSource;
|
MediaSource mediaSource;
|
||||||
@ -593,23 +631,16 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
reLayout(exoPlayerView);
|
reLayout(exoPlayerView);
|
||||||
eventEmitter.loadStart();
|
eventEmitter.loadStart();
|
||||||
loadVideoStarted = true;
|
loadVideoStarted = true;
|
||||||
|
|
||||||
|
finishPlayerInitialization();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void finishPlayerInitialization() {
|
||||||
// Initializing the playerControlView
|
// Initializing the playerControlView
|
||||||
initializePlayerControl();
|
initializePlayerControl();
|
||||||
setControls(controls);
|
setControls(controls);
|
||||||
applyModifiers();
|
applyModifiers();
|
||||||
startBufferCheckTimer();
|
startBufferCheckTimer();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
self.playerNeedsSource = true;
|
|
||||||
Log.e("ExoPlayer Exception", "Failed to initialize Player!");
|
|
||||||
Log.e("ExoPlayer Exception", ex.toString());
|
|
||||||
eventEmitter.error(ex.toString(), ex, "1001");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException {
|
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray, int retryCount) throws UnsupportedDrmException {
|
||||||
|
Loading…
Reference in New Issue
Block a user