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); } }
@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); }