시스템 자막 설정 채택

Android TV는 사용자가 자막 환경설정을 중앙에서 설정하여 미디어 앱 전반에서 일관된 환경을 만들 수 있는 설정을 제공합니다.

이러한 설정을 사용하면 사용자가 자막을 사용 설정하고, 선호하는 언어를 선택하고, 필요에 따라 맞춤 자막 스타일을 정의할 수 있습니다. 사용자는 'Easy Reader'라고 하는 초등학교 3학년 수준의 단순화된 자막을 선호하는지 지정할 수도 있습니다.

이 가이드에서는 시스템에서 제공하는 자막 설정을 가져와 앱의 자막에 적용하는 방법을 보여줍니다.

선택한 자막 스타일의 미리보기를 포함한 자막 옵션은 설정 > 접근성 > 자막 에서 찾을 수 있습니다.

Android TV의 자막 설정 메뉴
그림 1. 자막 설정 페이지

CaptioningManager 가져오기

활동에서 CaptioningManager 서비스를 Context에서 가져옵니다.

CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);

자막 설정 변경 처리

CaptioningChangeListener 클래스를 구현하여 자막 설정 변경을 처리합니다.

if (captioningManager != null) {
  // Define a class to store the CaptionStyle details.
  CurrentCaptionStyle currentCaptionStyle = new CurrentCaptionStyle();
  // Define the listeners.
  captioningManager.addCaptioningChangeListener(new CaptioningChangeListener() {

    @Override
    public void onEnabledChanged(boolean enabled) {
      super.onEnabledChanged(enabled);
      Log.d(TAG, "onEnabledChanged");
      currentCaptionStyle.isEnabled = enabled;
    }

    @Override
    public void onLocaleChanged(@Nullable Locale locale) {
      super.onLocaleChanged(locale);
      Log.d(TAG, "onLocaleChanged");
      currentCaptionStyle.locale = locale;
      if (locale == null) {
        currentCaptionStyle.isEasyReaderEnabled = false;
      } else {
        currentCaptionStyle.isEasyReaderEnabled = locale.getVariant().contains("simple");
      }
    }

    @Override
    public void onFontScaleChanged(float fontScale) {
      super.onFontScaleChanged(fontScale);
      Log.d(TAG, "onFontScaleChanged");
      currentCaptionStyle.fontScale = fontScale;
    }

    @Override
    public void onUserStyleChanged(@NonNull CaptionStyle userStyle) {
      super.onUserStyleChanged(userStyle);
      Log.d(TAG, "onUserStyleChanged");
      currentCaptionStyle.hasBackgroundColor = userStyle.hasBackgroundColor();
      currentCaptionStyle.backgroundColor = userStyle.backgroundColor;
      currentCaptionStyle.backgroundOpacity = userStyle.backgroundColor >>> 24;
      currentCaptionStyle.hasForegroundColor = userStyle.hasForegroundColor();
      currentCaptionStyle.foregroundColor = userStyle.foregroundColor;
      currentCaptionStyle.foregroundOpacity = userStyle.foregroundColor >>> 24;
      currentCaptionStyle.hasWindowColor = userStyle.hasWindowColor();
      currentCaptionStyle.windowColor = userStyle.windowColor;
      currentCaptionStyle.windowOpacity = userStyle.windowColor >>> 24;
      currentCaptionStyle.hasEdgeColor = userStyle.hasEdgeColor();
      currentCaptionStyle.edgeColor = userStyle.edgeColor;
      currentCaptionStyle.hasEdgeType = userStyle.hasEdgeType();
      currentCaptionStyle.edgeType = userStyle.edgeType;
      currentCaptionStyle.typeFace = userStyle.getTypeface();
    }

  });
}

또는 getUserStyle 메서드를 직접 호출합니다.

CaptionStyle systemCaptionStyle = captioningManager.getUserStyle();