mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add missing null check.
The system services may return a null value if the service is not available. Guard against this by falling back to default values. PiperOrigin-RevId: 319187882
This commit is contained in:
parent
316f8a88cd
commit
f8217140d7
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user