- 内置字幕默认选择中文

- 内置字幕显示bug修复
- 字幕样式默认白色黑边
- 字幕样式新增少女粉
- 去掉字幕搜索结果过滤
pull/54/head
okjackcaptain 3 years ago
parent 794602e90a
commit 38b7df4fff
  1. 4
      app/src/main/java/com/github/tvbox/osc/player/TrackInfo.java
  2. 7
      app/src/main/java/com/github/tvbox/osc/subtitle/widget/SimpleSubtitleView.java
  3. 49
      app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java
  4. 9
      app/src/main/java/com/github/tvbox/osc/ui/dialog/SearchSubtitleDialog.java
  5. 26
      app/src/main/java/com/github/tvbox/osc/ui/dialog/SubtitleDialog.java
  6. 49
      app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java
  7. 2
      app/src/main/res/layout/dialog_select.xml
  8. 54
      app/src/main/res/layout/dialog_subtitle.xml
  9. 4
      app/src/main/res/layout/player_vod_control_view.xml
  10. 1
      app/src/main/res/values/colors.xml

@ -26,8 +26,8 @@ public class TrackInfo {
public int getSelected(List<TrackInfoBean> list, boolean track) {
int i = 0;
for (TrackInfoBean audio : list) {
if (audio.selected) return track ? audio.index : i;
for (TrackInfoBean trackInfoBean : list) {
if (trackInfoBean.selected) return track ? trackInfoBean.index : i;
i++;
}
return 99999;

@ -92,7 +92,12 @@ public class SimpleSubtitleView extends TextView
setText(EMPTY_TEXT);
return;
}
setText(Html.fromHtml(subtitle.content));
String text = subtitle.content;
text = text.replaceAll("(?:\\r\\n)", "<br />");
text = text.replaceAll("(?:\\r)", "<br />");
text = text.replaceAll("(?:\\n)", "<br />");
text = text.replaceAll("\\{[\\s\\S]*\\}", "");
setText(Html.fromHtml(text));
}
@Override

@ -204,7 +204,11 @@ public class PlayActivity extends BaseActivity {
@Override
public void selectSubtitle() {
selectMySubtitle();
try {
selectMySubtitle();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
@ -230,10 +234,13 @@ public class PlayActivity extends BaseActivity {
}
}
void selectMySubtitle() {
void selectMySubtitle() throws Exception {
SubtitleDialog subtitleDialog = new SubtitleDialog(PlayActivity.this);
if (mController.mSubtitleView.hasInternal) {
int playerType = mVodPlayerCfg.getInt("pl");
if (mController.mSubtitleView.hasInternal && playerType == 1) {
subtitleDialog.selectInternal.setVisibility(View.VISIBLE);
} else {
subtitleDialog.selectInternal.setVisibility(View.GONE);
}
subtitleDialog.setSubtitleViewListener(new SubtitleDialog.SubtitleViewListener() {
@Override
@ -248,6 +255,10 @@ public class PlayActivity extends BaseActivity {
public void selectInternalSubtitle() {
selectMyInternalSubtitle();
}
@Override
public void setTextStyle(int style) {
setSubtitleViewTextStyle(style);
}
});
subtitleDialog.setSearchSubtitleListener(new SubtitleDialog.SearchSubtitleListener() {
@Override
@ -297,6 +308,16 @@ public class PlayActivity extends BaseActivity {
subtitleDialog.show();
}
void setSubtitleViewTextStyle(int style) {
if (style == 0) {
mController.mSubtitleView.setTextColor(getBaseContext().getResources().getColorStateList(R.color.color_FFFFFF));
mController.mSubtitleView.setShadowLayer(2, 1, 1, R.color.color_CC000000);
} else if (style == 1) {
mController.mSubtitleView.setTextColor(getBaseContext().getResources().getColorStateList(R.color.color_FFB6C1));
mController.mSubtitleView.setShadowLayer(2, 1, 1, R.color.color_FFFFFF);
}
}
void selectMyAudioTrack() {
AbstractPlayer mediaPlayer = mVideoView.getMediaPlayer();
if (!(mediaPlayer instanceof IjkMediaPlayer)) {
@ -341,9 +362,10 @@ public class PlayActivity extends BaseActivity {
@Override
public String getDisplay(TrackInfoBean val) {
// return val.index + " : " + val.language;
String str = val.name.substring(val.name.substring(0, val.name.indexOf(",")).length()+1).trim();
return val.index + " : " + str;
String name = val.name.replace("AUDIO,", "");
name = name.replace("N/A,", "");
name = name.replace(" ", "");
return val.index + " : " + val.language + " : " + name;
}
}, new DiffUtil.ItemCallback<TrackInfoBean>() {
@Override
@ -497,8 +519,8 @@ public class PlayActivity extends BaseActivity {
}
private void initSubtitleView() {
TrackInfo trackInfo = null;
if (mVideoView.getMediaPlayer() instanceof IjkMediaPlayer) {
TrackInfo trackInfo = null;
trackInfo = ((IjkMediaPlayer)(mVideoView.getMediaPlayer())).getTrackInfo();
if (trackInfo != null && trackInfo.getSubtitle().size() > 0) {
mController.mSubtitleView.hasInternal = true;
@ -525,6 +547,19 @@ public class PlayActivity extends BaseActivity {
} else {
if (mController.mSubtitleView.hasInternal) {
mController.mSubtitleView.isInternal = true;
if (trackInfo != null) {
List<TrackInfoBean> subtitleTrackList = trackInfo.getSubtitle();
int selectedIndex = trackInfo.getSubtitleSelected(true);
for(TrackInfoBean subtitleTrackInfoBean : subtitleTrackList) {
String lowerLang = subtitleTrackInfoBean.language.toLowerCase();
if (lowerLang.startsWith("zh") || lowerLang.startsWith("ch")) {
if (selectedIndex != subtitleTrackInfoBean.index) {
((IjkMediaPlayer)(mVideoView.getMediaPlayer())).setTrack(subtitleTrackInfoBean.index);
break;
}
}
}
}
}
}
}

@ -150,15 +150,6 @@ public class SearchSubtitleDialog extends BaseDialog {
});
return;
}
//过滤结果
ArrayList<Subtitle> data_new=new ArrayList<>();
for (int i=0;i< data.size();i++){
Subtitle subtitle = data.get(i);
if(subtitle.getName().contains(searchWord)){
data_new.add(subtitle);
}
}
data = data_new;
if (data.size() > 0) {
mGridView.requestFocus();

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -24,6 +25,8 @@ public class SubtitleDialog extends BaseDialog {
private TextView subtitleTimeMinus;
private TextView subtitleTimeText;
private TextView subtitleTimePlus;
private TextView subtitleStyleOne;
private TextView subtitleStyleTwo;
private SearchSubtitleListener mSearchSubtitleListener;
private LocalFileChooserListener mLocalFileChooserListener;
@ -48,6 +51,8 @@ public class SubtitleDialog extends BaseDialog {
subtitleTimeMinus = findViewById(R.id.subtitleTimeMinus);
subtitleTimeText = findViewById(R.id.subtitleTimeText);
subtitleTimePlus = findViewById(R.id.subtitleTimePlus);
subtitleStyleOne = findViewById(R.id.subtitleStyleOne);
subtitleStyleTwo = findViewById(R.id.subtitleStyleTwo);
selectLocal.setOnClickListener(new View.OnClickListener() {
@Override
@ -153,6 +158,26 @@ public class SubtitleDialog extends BaseDialog {
mSubtitleViewListener.selectInternalSubtitle();
}
});
subtitleStyleOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int style = 0;
dismiss();
mSubtitleViewListener.setTextStyle(style);
Toast.makeText(getContext(), "设置样式成功", Toast.LENGTH_SHORT).show();
}
});
subtitleStyleTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int style = 1;
dismiss();
mSubtitleViewListener.setTextStyle(style);
Toast.makeText(getContext(), "设置样式成功", Toast.LENGTH_SHORT).show();
}
});
}
public void setLocalFileChooserListener(LocalFileChooserListener localFileChooserListener) {
@ -179,5 +204,6 @@ public class SubtitleDialog extends BaseDialog {
void setTextSize(int size);
void setSubtitleDelay(int milliseconds);
void selectInternalSubtitle();
void setTextStyle(int style);
}
}

@ -203,7 +203,11 @@ public class PlayFragment extends BaseLazyFragment {
@Override
public void selectSubtitle() {
selectMySubtitle();
try {
selectMySubtitle();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
@ -229,10 +233,13 @@ public class PlayFragment extends BaseLazyFragment {
}
}
void selectMySubtitle() {
void selectMySubtitle() throws Exception {
SubtitleDialog subtitleDialog = new SubtitleDialog(getActivity());
if (mController.mSubtitleView.hasInternal) {
int playerType = mVodPlayerCfg.getInt("pl");
if (mController.mSubtitleView.hasInternal && playerType == 1) {
subtitleDialog.selectInternal.setVisibility(View.VISIBLE);
} else {
subtitleDialog.selectInternal.setVisibility(View.GONE);
}
subtitleDialog.setSubtitleViewListener(new SubtitleDialog.SubtitleViewListener() {
@Override
@ -243,11 +250,14 @@ public class PlayFragment extends BaseLazyFragment {
public void setSubtitleDelay(int milliseconds) {
mController.mSubtitleView.setSubtitleDelay(milliseconds);
}
@Override
public void selectInternalSubtitle() {
selectMyInternalSubtitle();
}
@Override
public void setTextStyle(int style) {
setSubtitleViewTextStyle(style);
}
});
subtitleDialog.setSearchSubtitleListener(new SubtitleDialog.SearchSubtitleListener() {
@Override
@ -297,6 +307,15 @@ public class PlayFragment extends BaseLazyFragment {
subtitleDialog.show();
}
void setSubtitleViewTextStyle(int style) {
if (style == 0) {
mController.mSubtitleView.setTextColor(getContext().getResources().getColorStateList(R.color.color_FFFFFF));
mController.mSubtitleView.setShadowLayer(2, 1, 1, R.color.color_CC000000);
} else if (style == 1) {
mController.mSubtitleView.setTextColor(getContext().getResources().getColorStateList(R.color.color_FFB6C1));
mController.mSubtitleView.setShadowLayer(2, 1, 1, R.color.color_FFFFFF);
}
}
void selectMyAudioTrack() {
AbstractPlayer mediaPlayer = mVideoView.getMediaPlayer();
@ -342,9 +361,10 @@ public class PlayFragment extends BaseLazyFragment {
@Override
public String getDisplay(TrackInfoBean val) {
// return val.index + " : " + val.language;
String str = val.name.substring(val.name.substring(0, val.name.indexOf(",")).length()+1).trim();
return val.index + " : " + str;
String name = val.name.replace("AUDIO,", "");
name = name.replace("N/A,", "");
name = name.replace(" ", "");
return val.index + " : " + val.language + " : " + name;
}
}, new DiffUtil.ItemCallback<TrackInfoBean>() {
@Override
@ -496,8 +516,8 @@ public class PlayFragment extends BaseLazyFragment {
}
private void initSubtitleView() {
TrackInfo trackInfo = null;
if (mVideoView.getMediaPlayer() instanceof IjkMediaPlayer) {
TrackInfo trackInfo = null;
trackInfo = ((IjkMediaPlayer)(mVideoView.getMediaPlayer())).getTrackInfo();
if (trackInfo != null && trackInfo.getSubtitle().size() > 0) {
mController.mSubtitleView.hasInternal = true;
@ -524,6 +544,19 @@ public class PlayFragment extends BaseLazyFragment {
} else {
if (mController.mSubtitleView.hasInternal) {
mController.mSubtitleView.isInternal = true;
if (trackInfo != null) {
List<TrackInfoBean> subtitleTrackList = trackInfo.getSubtitle();
int selectedIndex = trackInfo.getSubtitleSelected(true);
for(TrackInfoBean subtitleTrackInfoBean : subtitleTrackList) {
String lowerLang = subtitleTrackInfoBean.language.toLowerCase();
if (lowerLang.startsWith("zh") || lowerLang.startsWith("ch")) {
if (selectedIndex != subtitleTrackInfoBean.index) {
((IjkMediaPlayer)(mVideoView.getMediaPlayer())).setTrack(subtitleTrackInfoBean.index);
break;
}
}
}
}
}
}
}

@ -6,7 +6,7 @@
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="@dimen/vs_440"
android:layout_width="@dimen/vs_480"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/shape_dialog_bg_main">

@ -109,6 +109,60 @@
</LinearLayout>
<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="@dimen/vs_10"
android:layout_width="@dimen/vs_480"
android:layout_height="@dimen/vs_60">
<TextView
android:id="@+id/subtitleStyleOne"
android:layout_width="@dimen/vs_140"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button_dialog_main"
android:focusable="true"
android:gravity="center"
android:padding="@dimen/vs_10"
android:text="字幕样式一"
android:textColor="@color/color_FFFFFF"
android:shadowColor="@color/color_CC000000"
android:shadowRadius="2"
android:shadowDx="1"
android:shadowDy="1"
android:textSize="@dimen/ts_24" />
<TextView
android:layout_width="@dimen/vs_120"
android:layout_height="@dimen/vs_60"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginLeft="@dimen/vs_40"
android:layout_marginRight="@dimen/vs_40"
android:text=""
android:textSize="@dimen/ts_40" />
<TextView
android:id="@+id/subtitleStyleTwo"
android:layout_width="@dimen/vs_140"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button_dialog_main"
android:focusable="true"
android:gravity="center"
android:padding="@dimen/vs_10"
android:text="字幕样式二"
android:textStyle="bold"
android:textColor="@color/color_FFB6C1"
android:shadowColor="@color/color_FFFFFF"
android:shadowRadius="2"
android:shadowDx="1"
android:shadowDy="1"
android:textSize="@dimen/ts_24" />
</LinearLayout>
<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"

@ -98,6 +98,10 @@
android:paddingRight="@dimen/vs_20"
android:paddingBottom="@dimen/vs_15"
android:text=""
android:shadowColor="@color/color_CC000000"
android:shadowRadius="2"
android:shadowDx="1"
android:shadowDy="1"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold"/>

@ -12,6 +12,7 @@
<color name="color_BD0CADE2">#BD0CADE2</color>
<color name="color_FF0057">#FF0057</color>
<color name="color_FF5F00">#FF5F00</color>
<color name="color_FFB6C1">#FFB6C1</color>
<color name="color_3D3D3D">#3D3D3D</color>
<color name="color_32364E">#32364E</color>
<color name="color_6632364E">#6632364E</color>

Loading…
Cancel
Save