VEX-5825: Android player error handling improvements (#10)
Improve error handling.
This commit is contained in:
parent
a0b679cc07
commit
2fcc1de626
@ -43,6 +43,7 @@ import com.google.android.exoplayer2.drm.DrmSessionManager;
|
|||||||
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
||||||
import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
|
import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
|
||||||
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
|
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
|
||||||
|
import com.google.android.exoplayer2.drm.MediaDrmCallbackException;
|
||||||
import com.google.android.exoplayer2.drm.UnsupportedDrmException;
|
import com.google.android.exoplayer2.drm.UnsupportedDrmException;
|
||||||
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
|
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
|
||||||
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
|
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
|
||||||
@ -459,6 +460,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
|
ExoTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
|
||||||
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
|
trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
|
||||||
@ -509,7 +511,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
|
int errorStringId = Util.SDK_INT < 18 ? R.string.error_drm_not_supported
|
||||||
: (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
|
: (e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
|
||||||
? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
|
? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
|
||||||
eventEmitter.error(getResources().getString(errorStringId), e);
|
eventEmitter.error(getResources().getString(errorStringId), e, "3003");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,8 +547,16 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
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);
|
}, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrmSessionManager buildDrmSessionManager(UUID uuid,
|
private DrmSessionManager buildDrmSessionManager(UUID uuid,
|
||||||
@ -567,6 +577,9 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) {
|
private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) {
|
||||||
|
if (uri == null) {
|
||||||
|
throw new IllegalStateException("Invalid video uri");
|
||||||
|
}
|
||||||
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
|
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
|
||||||
: uri.getLastPathSegment());
|
: uri.getLastPathSegment());
|
||||||
config.setDisableDisconnectError(this.disableDisconnectError);
|
config.setDisableDisconnectError(this.disableDisconnectError);
|
||||||
@ -1015,6 +1028,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerError(ExoPlaybackException e) {
|
public void onPlayerError(ExoPlaybackException e) {
|
||||||
String errorString = "ExoPlaybackException type : " + e.type;
|
String errorString = "ExoPlaybackException type : " + e.type;
|
||||||
|
String errorCode = "2001"; // Playback error code 2xxx (2001 - unknown playback exception)
|
||||||
Exception ex = e;
|
Exception ex = e;
|
||||||
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
|
||||||
Exception cause = e.getRendererException();
|
Exception cause = e.getRendererException();
|
||||||
@ -1024,24 +1038,45 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
(MediaCodecRenderer.DecoderInitializationException) cause;
|
(MediaCodecRenderer.DecoderInitializationException) cause;
|
||||||
if (decoderInitializationException.codecInfo.name == null) {
|
if (decoderInitializationException.codecInfo.name == null) {
|
||||||
if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
|
if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
|
||||||
|
errorCode = "2011";
|
||||||
errorString = getResources().getString(R.string.error_querying_decoders);
|
errorString = getResources().getString(R.string.error_querying_decoders);
|
||||||
} else if (decoderInitializationException.secureDecoderRequired) {
|
} else if (decoderInitializationException.secureDecoderRequired) {
|
||||||
|
errorCode = "2012";
|
||||||
errorString = getResources().getString(R.string.error_no_secure_decoder,
|
errorString = getResources().getString(R.string.error_no_secure_decoder,
|
||||||
decoderInitializationException.mimeType);
|
decoderInitializationException.mimeType);
|
||||||
} else {
|
} else {
|
||||||
|
errorCode = "2013";
|
||||||
errorString = getResources().getString(R.string.error_no_decoder,
|
errorString = getResources().getString(R.string.error_no_decoder,
|
||||||
decoderInitializationException.mimeType);
|
decoderInitializationException.mimeType);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
errorCode = "2014";
|
||||||
errorString = getResources().getString(R.string.error_instantiating_decoder,
|
errorString = getResources().getString(R.string.error_instantiating_decoder,
|
||||||
decoderInitializationException.codecInfo.name);
|
decoderInitializationException.codecInfo.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (e.type == ExoPlaybackException.TYPE_SOURCE) {
|
else if (e.type == ExoPlaybackException.TYPE_SOURCE) {
|
||||||
|
Exception cause = e.getSourceException();
|
||||||
|
if (cause instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
|
||||||
|
errorCode = "3004";
|
||||||
|
errorString = getResources().getString(R.string.unrecognized_media_format);
|
||||||
|
} else if(cause instanceof MediaDrmCallbackException) {
|
||||||
|
errorCode = "3005";
|
||||||
|
errorString = getResources().getString(R.string.unrecognized_media_format);
|
||||||
|
} else {
|
||||||
|
errorCode = "2021";
|
||||||
errorString = getResources().getString(R.string.unrecognized_media_format);
|
errorString = getResources().getString(R.string.unrecognized_media_format);
|
||||||
}
|
}
|
||||||
eventEmitter.error(errorString, ex);
|
if (cause != null) {
|
||||||
|
Throwable rootCause = cause.getCause();
|
||||||
|
if (rootCause instanceof MediaDrmCallbackException) {
|
||||||
|
errorCode = "3005";
|
||||||
|
errorString = getResources().getString(R.string.unrecognized_media_format);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eventEmitter.error(errorString, ex, errorCode);
|
||||||
playerNeedsSource = true;
|
playerNeedsSource = true;
|
||||||
if (isBehindLiveWindow(e)) {
|
if (isBehindLiveWindow(e)) {
|
||||||
clearResumePosition();
|
clearResumePosition();
|
||||||
@ -1491,7 +1526,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
@Override
|
@Override
|
||||||
public void onDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, Exception e) {
|
public void onDrmSessionManagerError(int windowIndex, MediaSource.MediaPeriodId mediaPeriodId, Exception e) {
|
||||||
Log.d("DRM Info", "onDrmSessionManagerError");
|
Log.d("DRM Info", "onDrmSessionManagerError");
|
||||||
eventEmitter.error("onDrmSessionManagerError", e);
|
eventEmitter.error("onDrmSessionManagerError", e, "3002");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,6 +15,8 @@ import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
|
|||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
class VideoEventEmitter {
|
class VideoEventEmitter {
|
||||||
|
|
||||||
@ -130,6 +132,8 @@ class VideoEventEmitter {
|
|||||||
private static final String EVENT_PROP_ERROR = "error";
|
private static final String EVENT_PROP_ERROR = "error";
|
||||||
private static final String EVENT_PROP_ERROR_STRING = "errorString";
|
private static final String EVENT_PROP_ERROR_STRING = "errorString";
|
||||||
private static final String EVENT_PROP_ERROR_EXCEPTION = "errorException";
|
private static final String EVENT_PROP_ERROR_EXCEPTION = "errorException";
|
||||||
|
private static final String EVENT_PROP_ERROR_TRACE = "errorStackTrace";
|
||||||
|
private static final String EVENT_PROP_ERROR_CODE = "errorCode";
|
||||||
|
|
||||||
private static final String EVENT_PROP_TIMED_METADATA = "metadata";
|
private static final String EVENT_PROP_TIMED_METADATA = "metadata";
|
||||||
|
|
||||||
@ -243,9 +247,25 @@ class VideoEventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void error(String errorString, Exception exception) {
|
void error(String errorString, Exception exception) {
|
||||||
|
_error(errorString, exception, "0001");
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(String errorString, Exception exception, String errorCode) {
|
||||||
|
_error(errorString, exception, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _error(String errorString, Exception exception, String errorCode) {
|
||||||
|
// Prepare stack trace
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
|
exception.printStackTrace(pw);
|
||||||
|
String stackTrace = sw.toString();
|
||||||
|
|
||||||
WritableMap error = Arguments.createMap();
|
WritableMap error = Arguments.createMap();
|
||||||
error.putString(EVENT_PROP_ERROR_STRING, errorString);
|
error.putString(EVENT_PROP_ERROR_STRING, errorString);
|
||||||
error.putString(EVENT_PROP_ERROR_EXCEPTION, exception.toString());
|
error.putString(EVENT_PROP_ERROR_EXCEPTION, exception.toString());
|
||||||
|
error.putString(EVENT_PROP_ERROR_CODE, errorCode);
|
||||||
|
error.putString(EVENT_PROP_ERROR_TRACE, stackTrace);
|
||||||
WritableMap event = Arguments.createMap();
|
WritableMap event = Arguments.createMap();
|
||||||
event.putMap(EVENT_PROP_ERROR, error);
|
event.putMap(EVENT_PROP_ERROR, error);
|
||||||
receiveEvent(EVENT_ERROR, event);
|
receiveEvent(EVENT_ERROR, event);
|
||||||
|
Loading…
Reference in New Issue
Block a user