@Override public void onCues(List<Cue> cues) { if (subtitleView != null) { subtitleView.onCues(cues); } }
@Override public void onCues(List<Cue> cues) { setCues(cues); }
@Override protected void setupSubtitleView(@NonNull SubtitleView view, final float captionScale, @NonNull final CaptionStyleCompat captionStyle) { float captionRatio = (captionScale - 1f) / 5f + 1f; view.setFractionalTextSize(SubtitleView.DEFAULT_TEXT_SIZE_FRACTION * captionRatio); view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT)); view.setStyle(captionStyle); }
/** * Sets the caption style to be equivalent to the one returned by * {@link CaptioningManager#getUserStyle()}, or to a default style before API level 19. */ public void setUserDefaultStyle() { setStyle( Util.SDK_INT >= 19 && isCaptionManagerEnabled() && !isInEditMode() ? getUserCaptionStyleV19() : CaptionStyleCompat.DEFAULT); }
/** * Sets the text size to one derived from {@link CaptioningManager#getFontScale()}, or to a * default size before API level 19. */ public void setUserDefaultTextSize() { float fontScale = Util.SDK_INT >= 19 && !isInEditMode() ? getUserCaptionFontScaleV19() : 1f; setFractionalTextSize(DEFAULT_TEXT_SIZE_FRACTION * fontScale); }
subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize();
@Override protected void setupSubtitleView(@NonNull SubtitleView view, final float captionScale, @NonNull final CaptionStyleCompat captionStyle) { final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final int minimumLength = Math.min(metrics.heightPixels, metrics.widthPixels); final float captionRatioInverse = 20f + 4f * (1f - captionScale); view.setFixedTextSize(TypedValue.COMPLEX_UNIT_PX, (float) minimumLength / captionRatioInverse); view.setApplyEmbeddedStyles(captionStyle.equals(CaptionStyleCompat.DEFAULT)); view.setStyle(captionStyle); }
/** * Sets the text size to be a fraction of the view's remaining height after its top and bottom * padding have been subtracted. * <p> * Equivalent to {@code #setFractionalTextSize(fractionOfHeight, false)}. * * @param fractionOfHeight A fraction between 0 and 1. */ public void setFractionalTextSize(float fractionOfHeight) { setFractionalTextSize(fractionOfHeight, false); }
/** * Set the text size to a given unit and value. * <p> * See {@link TypedValue} for the possible dimension units. * * @param unit The desired dimension unit. * @param size The desired size in the given units. */ public void setFixedTextSize(int unit, float size) { Context context = getContext(); Resources resources; if (context == null) { resources = Resources.getSystem(); } else { resources = context.getResources(); } setTextSize( Cue.TEXT_SIZE_TYPE_ABSOLUTE, TypedValue.applyDimension(unit, size, resources.getDisplayMetrics())); }
/** * Sets the cues to be displayed by the view. * * @param cues The cues to display, or null to clear the cues. */ public void setCues(@Nullable List<Cue> cues) { if (this.cues == cues) { return; } this.cues = cues; // Ensure we have sufficient painters. int cueCount = (cues == null) ? 0 : cues.size(); while (painters.size() < cueCount) { painters.add(new SubtitlePainter(getContext())); } // Invalidate to trigger drawing. invalidate(); }
@TargetApi(19) private boolean isCaptionManagerEnabled() { CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); return captioningManager.isEnabled(); }
subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize();
@TargetApi(19) private float getUserCaptionFontScaleV19() { CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); return captioningManager.getFontScale(); }
subtitleView.setUserDefaultStyle(); subtitleView.setUserDefaultTextSize();
@Override public void initPlayer(final boolean playOnReady) { super.initPlayer(playOnReady); // Setup video view simpleExoPlayer.setVideoSurfaceView(surfaceView); simpleExoPlayer.addVideoListener(this); // Setup subtitle view simpleExoPlayer.addTextOutput(cues -> subtitleView.onCues(cues)); // Setup audio session with onboard equalizer if (Build.VERSION.SDK_INT >= 21) { trackSelector.setParameters(trackSelector.buildUponParameters() .setTunnelingAudioSessionId(C.generateAudioSessionIdV21(context))); } }
subtitleView.setCues(null);
@TargetApi(19) private CaptionStyleCompat getUserCaptionStyleV19() { CaptioningManager captioningManager = (CaptioningManager) getContext().getSystemService(Context.CAPTIONING_SERVICE); return CaptionStyleCompat.createFromCaptionStyle(captioningManager.getUserStyle()); }
@Override public void onCues(List<Cue> cues) { if (subtitleView != null) { subtitleView.onCues(cues); } }
subtitleView.setCues(null);
@Override public void onCues(List<Cue> cues) { if (subtitleView != null) { subtitleView.onCues(cues); } }