diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java index e066fa0f8a..72a3a8384e 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitleView.java @@ -327,23 +327,28 @@ public final class SubtitleView extends FrameLayout implements TextOutput { @RequiresApi(19) private boolean isCaptionManagerEnabled() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return captioningManager.isEnabled(); + return captioningManager != null && captioningManager.isEnabled(); } @RequiresApi(19) private float getUserCaptionFontScaleV19() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return captioningManager.getFontScale(); + return captioningManager == null ? 1f : captioningManager.getFontScale(); } @RequiresApi(19) private CaptionStyleCompat getUserCaptionStyleV19() { + @Nullable CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); - return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); + return captioningManager == null + ? CaptionStyleCompat.DEFAULT + : CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); } private void updateOutput() {