static NoPlayer.PlayerError map(RuntimeException unexpectedException, String message) { if (unexpectedException instanceof EGLSurfaceTexture.GlException) { return new NoPlayerError(PlayerErrorType.UNEXPECTED, DetailErrorType.EGL_OPERATION_ERROR, message); } if (unexpectedException instanceof DefaultAudioSink.InvalidAudioTrackTimestampException) { return new NoPlayerError(PlayerErrorType.UNEXPECTED, DetailErrorType.SPURIOUS_AUDIO_TRACK_TIMESTAMP_ERROR, message); } if (unexpectedException instanceof IllegalStateException && message.contains("Multiple renderer media clocks")) { return new NoPlayerError(PlayerErrorType.UNEXPECTED, DetailErrorType.MULTIPLE_RENDERER_MEDIA_CLOCK_ENABLED_ERROR, message); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && unexpectedException instanceof MediaCodec.CodecException) { String errorMessage = ErrorFormatter.formatCodecException((MediaCodec.CodecException) unexpectedException); return new NoPlayerError(PlayerErrorType.UNEXPECTED, DetailErrorType.UNEXPECTED_CODEC_ERROR, errorMessage); } return new NoPlayerError(PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, message); } }
public static NoPlayer.PlayerError errorFor(ExoPlaybackException exception) { String message = ErrorFormatter.formatMessage(exception.getCause()); switch (exception.type) { case ExoPlaybackException.TYPE_SOURCE: return SourceErrorMapper.map(exception.getSourceException(), message); case ExoPlaybackException.TYPE_RENDERER: return RendererErrorMapper.map(exception.getRendererException(), message); case ExoPlaybackException.TYPE_UNEXPECTED: return UnexpectedErrorMapper.map(exception.getUnexpectedException(), message); default: return new NoPlayerError(PlayerErrorType.UNKNOWN, DetailErrorType.UNKNOWN, message); } } }
@Test public void givenThrowable_whenFormattingMessage_thenReturnsExpectedMessageFormat() { String expectedFormat = "com.novoda.noplayer.internal.exoplayer.error.ErrorFormatterTest$IncorrectFormatThrowable: message"; String actualFormat = ErrorFormatter.formatMessage(new IncorrectFormatThrowable(MESSAGE)); assertThat(actualFormat).isEqualTo(expectedFormat); }
@Test public void givenMediaCodecException_whenFormattingMessage_thenReturnsExpectedMessageFormat() { MediaCodec.CodecException codecException = mock(MediaCodec.CodecException.class); given(codecException.getDiagnosticInfo()).willReturn("android.media.MediaCodec.error_+1234"); given(codecException.isTransient()).willReturn(true); given(codecException.isRecoverable()).willReturn(false); String expectedFormat = "diagnosticInformation=android.media.MediaCodec.error_+1234 : isTransient=true : isRecoverable=false"; String actualFormat = ErrorFormatter.formatCodecException(codecException); assertThat(actualFormat).isEqualTo(expectedFormat); }