Clean up
This commit is contained in:
parent
88f32ae3c8
commit
2f77765fe2
@ -512,6 +512,49 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
// Initialize core configuration and listeners
|
||||||
|
initializePlayerCore(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerNeedsSource && srcUri != null) {
|
||||||
|
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 initialization must run on a different thread
|
||||||
|
initializePlayerDrm(self);
|
||||||
|
|
||||||
|
// 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(self);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initializePlayerSource(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} 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 initializePlayerCore(ReactExoplayerView self) {
|
||||||
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
|
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
|
||||||
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
|
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
|
||||||
trackSelector.setParameters(trackSelector.buildUponParameters()
|
trackSelector.setParameters(trackSelector.buildUponParameters()
|
||||||
@ -549,45 +592,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
player.setPlaybackParameters(params);
|
player.setPlaybackParameters(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerNeedsSource && srcUri != null) {
|
private void initializePlayerDrm(ReactExoplayerView self) {
|
||||||
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 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 {
|
||||||
@ -607,7 +612,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializePlayerSource() {
|
private void initializePlayerSource(ReactExoplayerView self) {
|
||||||
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
ArrayList<MediaSource> mediaSourceList = buildTextSources();
|
||||||
MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager);
|
MediaSource videoSource = buildMediaSource(srcUri, extension, drmSessionManager);
|
||||||
MediaSource mediaSource;
|
MediaSource mediaSource;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user