Skip to content

Commit

Permalink
link to #4045
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Nov 4, 2024
1 parent 4969859 commit 9409386
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void onClick(View v) {
}
});

binding.detailPlayer.setSubTitle("http://img.cdn.guoshuyu.cn/subtitle2.srt");
binding.detailPlayer.setSubTitle("http://img.cdn.guoshuyu.cn/subtitle.srt");
}

@Override
Expand Down Expand Up @@ -239,6 +239,6 @@ private GSYVideoPlayer getCurPlay() {


private String getUrl() {
return "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
return "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear3/prog_index.m3u8";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import androidx.media3.common.Metadata;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.Player;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.common.text.Cue;
import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.datasource.DefaultHttpDataSource;
Expand Down Expand Up @@ -60,7 +61,10 @@ protected void prepareAsyncInternal() {
@Override
public void run() {
if (mTrackSelector == null) {
mTrackSelector = new DefaultTrackSelector(mAppContext);
///todo 这里设置 setSelectUndeterminedTextLanguage 无视语言选择
mTrackSelector = new DefaultTrackSelector(mAppContext,
new TrackSelectionParameters.Builder(mAppContext).
setSelectUndeterminedTextLanguage(true).build());
}
mEventLogger = new EventLogger(mTrackSelector);
boolean preferExtensionDecoders = true;
Expand Down Expand Up @@ -108,12 +112,12 @@ public MediaSource getTextSource(Uri subTitle) {
//todo C.SELECTION_FLAG_AUTOSELECT language MimeTypes
Format textFormat = new Format.Builder()
/// 其他的比如 text/x-ssa ,text/vtt,application/ttml+xml 等等
.setSampleMimeType(MimeTypes.APPLICATION_SUBRIP)
.setSampleMimeType(MimeTypes.APPLICATION_MEDIA3_CUES)
.setSelectionFlags(C.SELECTION_FLAG_FORCED)
/// 如果出现字幕不显示,可以通过修改这个语音去对应,
// 这个问题在内部的 selectTextTrack 时,TextTrackScore 通过 getFormatLanguageScore 方法判断语言获取匹配不上
// 就会不出现字幕
.setLanguage("en")
.setLanguage("zh-cn")
.build();

MediaItem.SubtitleConfiguration subtitle = new MediaItem.SubtitleConfiguration.Builder(subTitle)
Expand Down

0 comments on commit 9409386

Please sign in to comment.