diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java index e25b8ae863..206d6deea7 100644 --- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java +++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/VideoManager.java @@ -2,7 +2,9 @@ import android.content.Context; import android.content.res.Configuration; +import android.graphics.Color; import android.graphics.PixelFormat; +import android.graphics.Point; import android.media.audiofx.DynamicsProcessing; import android.media.audiofx.DynamicsProcessing.Limiter; import android.media.audiofx.Equalizer; @@ -15,6 +17,7 @@ import android.view.ViewGroup; import android.widget.FrameLayout; +import androidx.annotation.Dimension; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -35,6 +38,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionOverride; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.CaptionStyleCompat; import com.google.android.exoplayer2.ui.PlayerView; import com.google.common.collect.ImmutableSet; @@ -79,6 +83,13 @@ public class VideoManager implements IVLCVout.OnNewVideoLayoutListener { private Media mCurrentMedia; private VlcEventHandler mVlcHandler = new VlcEventHandler(); private Handler mHandler = new Handler(); + + private final UserPreferences userPreferences = KoinJavaComponent.get(UserPreferences.class); + private final int subtitlesSize = userPreferences.get(UserPreferences.Companion.getSubtitlesSize()); + private final long subtitlesTextColor = userPreferences.get(UserPreferences.Companion.getSubtitlesTextColor()); + private final boolean subtitlesBackgroundEnabled = userPreferences.get(UserPreferences.Companion.getSubtitlesBackgroundEnabled()); + private final int subtitlesPosition = userPreferences.get(UserPreferences.Companion.getSubtitlePosition()); + private int mVideoHeight; private int mVideoWidth; private int mVideoVisibleHeight; @@ -119,6 +130,26 @@ public VideoManager(PlaybackOverlayActivity activity, View view) { .build()); mExoPlayerView = view.findViewById(R.id.exoPlayerView); + + int backgroundColor = subtitlesBackgroundEnabled ? Color.BLACK : Color.TRANSPARENT; + int captionStyle = subtitlesBackgroundEnabled ? + CaptionStyleCompat.EDGE_TYPE_NONE: + CaptionStyleCompat.EDGE_TYPE_OUTLINE; // For better contrast + mExoPlayerView.getSubtitleView().setStyle(new CaptionStyleCompat( + (int)subtitlesTextColor, + backgroundColor, + Color.TRANSPARENT, + captionStyle, + Color.BLACK, + null)); + + mExoPlayerView.getSubtitleView().setFixedTextSize(Dimension.PX, subtitlesSize); + + // need to convert the pixels to a fraction of the display's height + Point size = new Point(); + mActivity.getWindowManager().getDefaultDisplay().getSize(size); + mExoPlayerView.getSubtitleView().setBottomPaddingFraction(((float)(50+subtitlesPosition))/size.y); + mExoPlayerView.setPlayer(mExoPlayer); mExoPlayer.addListener(new Player.Listener() { @Override diff --git a/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt b/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt index 0950b04c1d..d0c0ac6c1b 100644 --- a/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt +++ b/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt @@ -207,7 +207,9 @@ class ExoPlayerProfile( }.toTypedArray() subtitleProfiles = arrayOf( + subtitleProfile(Codec.Subtitle.SRT, SubtitleDeliveryMethod.Embed), subtitleProfile(Codec.Subtitle.SRT, SubtitleDeliveryMethod.External), + subtitleProfile(Codec.Subtitle.SUBRIP, SubtitleDeliveryMethod.Embed), subtitleProfile(Codec.Subtitle.SUBRIP, SubtitleDeliveryMethod.External), subtitleProfile(Codec.Subtitle.ASS, SubtitleDeliveryMethod.Encode), subtitleProfile(Codec.Subtitle.SSA, SubtitleDeliveryMethod.Encode),