Fix ijk subtitle show

pull/123/head
FongMi 3 years ago
parent 6542d547a7
commit f83743d53e
  1. 27
      ijkplayer/src/main/java/tv/danmaku/ijk/media/player/ui/IjkVideoView.java
  2. 6
      ijkplayer/src/main/java/tv/danmaku/ijk/media/player/ui/SubtitleView.java
  3. 22
      ijkplayer/src/main/res/layout/ijk_player_view.xml

@ -9,6 +9,7 @@ import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.MediaController;
@ -20,6 +21,7 @@ import java.util.Map;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.player.IjkTimedText;
import tv.danmaku.ijk.media.player.R;
public class IjkVideoView extends FrameLayout implements MediaController.MediaPlayerControl {
@ -73,60 +75,47 @@ public class IjkVideoView extends FrameLayout implements MediaController.MediaPl
private int mVideoSarNum;
private int mVideoSarDen;
private FrameLayout contentFrame;
private SubtitleView subtitleView;
public IjkVideoView(Context context) {
super(context);
initVideoView(context);
initSubtitleView(context);
}
public IjkVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
initVideoView(context);
initSubtitleView(context);
}
public IjkVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initVideoView(context);
initSubtitleView(context);
}
public IjkVideoView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initVideoView(context);
initSubtitleView(context);
}
private void initVideoView(Context context) {
LayoutInflater.from(context).inflate(R.layout.ijk_player_view, this);
mAppContext = context.getApplicationContext();
contentFrame = findViewById(R.id.ijk_content_frame);
subtitleView = findViewById(R.id.ijk_subtitle);
mVideoWidth = 0;
mVideoHeight = 0;
mCurrentState = STATE_IDLE;
mTargetState = STATE_IDLE;
}
private void initSubtitleView(Context context) {
subtitleView = new SubtitleView(context);
LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
int space = Math.round(Utils.dp2px(context, 16));
params.setMargins(space, 0, space, space);
addView(subtitleView, params);
}
private void setRenderView(IRenderView renderView) {
clearRender();
mRenderView = renderView;
setResizeMode(mCurrentAspectRatio);
addView(mRenderView.getView(), new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
contentFrame.addView(mRenderView.getView(), 0, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
mRenderView.addRenderCallback(mSHCallback);
mRenderView.setVideoRotation(mVideoRotationDegree);
}
private void clearRender() {
if (mRenderView != null) {
removeView(mRenderView.getView());
contentFrame.removeView(mRenderView.getView());
mRenderView.removeRenderCallback(mSHCallback);
mRenderView = null;
}

@ -4,9 +4,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;
import androidx.annotation.Nullable;
@ -33,10 +31,6 @@ public class SubtitleView extends TextView {
private void init() {
strokeWidth = Utils.dp2px(getContext(), 0.6f);
setTypeface(Typeface.DEFAULT_BOLD);
setGravity(Gravity.CENTER);
setTextSize(16);
setZ(99);
}
@Override

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/ijk_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<tv.danmaku.ijk.media.player.ui.SubtitleView
android:id="@+id/ijk_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:gravity="center"
android:textSize="16sp"
android:textStyle="bold" />
</FrameLayout>
</merge>
Loading…
Cancel
Save