use of com.google.android.exoplayer2.drm.UnsupportedDrmException in project ExoPlayer by google.
the class MediaMetricsListener method getErrorInfo.
private static ErrorInfo getErrorInfo(PlaybackException error, Context context, boolean lastIoErrorForManifest) {
if (error.errorCode == PlaybackException.ERROR_CODE_REMOTE_ERROR) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_REMOTE, /* subErrorCode= */
0);
}
// Unpack the PlaybackException.
// TODO(b/190203080): Use error codes instead of the Exception's cause where possible.
boolean isRendererExoPlaybackException = false;
int rendererFormatSupport = C.FORMAT_UNSUPPORTED_TYPE;
if (error instanceof ExoPlaybackException) {
ExoPlaybackException exoPlaybackException = (ExoPlaybackException) error;
isRendererExoPlaybackException = exoPlaybackException.type == ExoPlaybackException.TYPE_RENDERER;
rendererFormatSupport = exoPlaybackException.rendererFormatSupport;
}
Throwable cause = checkNotNull(error.getCause());
if (cause instanceof IOException) {
if (cause instanceof HttpDataSource.InvalidResponseCodeException) {
int responseCode = ((HttpDataSource.InvalidResponseCodeException) cause).responseCode;
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_BAD_HTTP_STATUS, /* subErrorCode= */
responseCode);
} else if (cause instanceof HttpDataSource.InvalidContentTypeException || cause instanceof ParserException) {
return new ErrorInfo(lastIoErrorForManifest ? PlaybackErrorEvent.ERROR_PARSING_MANIFEST_MALFORMED : PlaybackErrorEvent.ERROR_PARSING_CONTAINER_MALFORMED, /* subErrorCode= */
0);
} else if (cause instanceof HttpDataSource.HttpDataSourceException || cause instanceof UdpDataSource.UdpDataSourceException) {
if (NetworkTypeObserver.getInstance(context).getNetworkType() == C.NETWORK_TYPE_OFFLINE) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NETWORK_UNAVAILABLE, /* subErrorCode= */
0);
} else {
@Nullable Throwable detailedCause = cause.getCause();
if (detailedCause instanceof UnknownHostException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_DNS_FAILED, /* subErrorCode= */
0);
} else if (detailedCause instanceof SocketTimeoutException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_CONNECTION_TIMEOUT, /* subErrorCode= */
0);
} else if (cause instanceof HttpDataSource.HttpDataSourceException && ((HttpDataSource.HttpDataSourceException) cause).type == HttpDataSource.HttpDataSourceException.TYPE_OPEN) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NETWORK_CONNECTION_FAILED, /* subErrorCode= */
0);
} else {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_CONNECTION_CLOSED, /* subErrorCode= */
0);
}
}
} else if (error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_BEHIND_LIVE_WINDOW, /* subErrorCode= */
0);
} else if (cause instanceof DrmSession.DrmSessionException) {
// Unpack DrmSessionException.
cause = checkNotNull(cause.getCause());
if (Util.SDK_INT >= 21 && cause instanceof MediaDrm.MediaDrmStateException) {
String diagnosticsInfo = ((MediaDrm.MediaDrmStateException) cause).getDiagnosticInfo();
int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
int errorCode = getDrmErrorCode(subErrorCode);
return new ErrorInfo(errorCode, subErrorCode);
} else if (Util.SDK_INT >= 23 && cause instanceof MediaDrmResetException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SYSTEM_ERROR, /* subErrorCode= */
0);
} else if (Util.SDK_INT >= 18 && cause instanceof NotProvisionedException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_PROVISIONING_FAILED, /* subErrorCode= */
0);
} else if (Util.SDK_INT >= 18 && cause instanceof DeniedByServerException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_DEVICE_REVOKED, /* subErrorCode= */
0);
} else if (cause instanceof UnsupportedDrmException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SCHEME_UNSUPPORTED, /* subErrorCode= */
0);
} else if (cause instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_CONTENT_ERROR, /* subErrorCode= */
0);
} else {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_OTHER, /* subErrorCode= */
0);
}
} else if (cause instanceof FileDataSource.FileDataSourceException && cause.getCause() instanceof FileNotFoundException) {
@Nullable Throwable notFoundCause = checkNotNull(cause.getCause()).getCause();
if (Util.SDK_INT >= 21 && notFoundCause instanceof ErrnoException && ((ErrnoException) notFoundCause).errno == OsConstants.EACCES) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_NO_PERMISSION, /* subErrorCode= */
0);
} else {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_FILE_NOT_FOUND, /* subErrorCode= */
0);
}
} else {
return new ErrorInfo(PlaybackErrorEvent.ERROR_IO_OTHER, /* subErrorCode= */
0);
}
} else if (isRendererExoPlaybackException && (rendererFormatSupport == C.FORMAT_UNSUPPORTED_TYPE || rendererFormatSupport == C.FORMAT_UNSUPPORTED_SUBTYPE)) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FORMAT_UNSUPPORTED, /* subErrorCode= */
0);
} else if (isRendererExoPlaybackException && rendererFormatSupport == C.FORMAT_EXCEEDS_CAPABILITIES) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FORMAT_EXCEEDS_CAPABILITIES, /* subErrorCode= */
0);
} else if (isRendererExoPlaybackException && rendererFormatSupport == C.FORMAT_UNSUPPORTED_DRM) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DRM_SCHEME_UNSUPPORTED, /* subErrorCode= */
0);
} else if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
@Nullable String diagnosticsInfo = ((MediaCodecRenderer.DecoderInitializationException) cause).diagnosticInfo;
int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODER_INIT_FAILED, subErrorCode);
} else if (cause instanceof MediaCodecDecoderException) {
@Nullable String diagnosticsInfo = ((MediaCodecDecoderException) cause).diagnosticInfo;
int subErrorCode = Util.getErrorCodeFromPlatformDiagnosticsInfo(diagnosticsInfo);
return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FAILED, subErrorCode);
} else if (cause instanceof OutOfMemoryError) {
return new ErrorInfo(PlaybackErrorEvent.ERROR_DECODING_FAILED, /* subErrorCode= */
0);
} else if (cause instanceof AudioSink.InitializationException) {
int subErrorCode = ((AudioSink.InitializationException) cause).audioTrackState;
return new ErrorInfo(PlaybackErrorEvent.ERROR_AUDIO_TRACK_INIT_FAILED, subErrorCode);
} else if (cause instanceof AudioSink.WriteException) {
int subErrorCode = ((AudioSink.WriteException) cause).errorCode;
return new ErrorInfo(PlaybackErrorEvent.ERROR_AUDIO_TRACK_WRITE_FAILED, subErrorCode);
} else if (Util.SDK_INT >= 16 && cause instanceof MediaCodec.CryptoException) {
int subErrorCode = ((MediaCodec.CryptoException) cause).getErrorCode();
int errorCode = getDrmErrorCode(subErrorCode);
return new ErrorInfo(errorCode, subErrorCode);
} else {
return new ErrorInfo(PlaybackErrorEvent.ERROR_PLAYER_OTHER, /* subErrorCode= */
0);
}
}
use of com.google.android.exoplayer2.drm.UnsupportedDrmException in project LeafPic by HoraApps.
the class PlayerActivity method initializePlayer.
// Internal methods
private void initializePlayer() {
Intent intent = getIntent();
boolean needNewPlayer = player == null;
if (needNewPlayer) {
TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper());
lastSeenTrackGroupArray = null;
UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
if (drmSchemeUuid != null) {
String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false);
int errorStringId = R.string.error_drm_unknown;
try {
drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
} catch (UnsupportedDrmException e) {
errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
}
if (drmSessionManager == null) {
showToast(errorStringId);
return;
}
}
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
player.addListener(new PlayerEventListener());
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(shouldAutoPlay);
}
String action = intent.getAction();
Uri[] uris;
String[] extensions;
if (intent.getData() != null && intent.getType() != null) {
uris = new Uri[] { intent.getData() };
extensions = new String[] { intent.getType() };
} else {
// TODO: 12/7/16 asdasd
showToast(getString(R.string.unexpected_intent_action, action));
return;
}
MediaSource[] mediaSources = new MediaSource[uris.length];
for (int i = 0; i < uris.length; i++) {
mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
}
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
if (haveResumePosition) {
player.seekTo(resumeWindow, resumePosition);
}
player.prepare(mediaSource, !haveResumePosition, false);
inErrorState = false;
supportInvalidateOptionsMenu();
}
Aggregations