Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading issues with embedded SUBRIP subtitles while using Exoplayer #2743

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +17,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand All @@ -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;

Expand Down Expand Up @@ -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.<UserPreferences>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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down