diff --git a/app/lint.xml b/app/lint.xml new file mode 100644 index 000000000..29fe194f4 --- /dev/null +++ b/app/lint.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitleDetailPlayer.java b/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitleDetailPlayer.java index c15f17ab0..f1f019a37 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitleDetailPlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitleDetailPlayer.java @@ -166,7 +166,7 @@ public void onClick(View v) { } }); - binding.detailPlayer.setSubTitle("http://img.cdn.guoshuyu.cn/subtitle.srt"); + binding.detailPlayer.setSubTitle("http://img.cdn.guoshuyu.cn/subtitle2.srt"); } @Override @@ -239,6 +239,6 @@ private GSYVideoPlayer getCurPlay() { private String getUrl() { - return "http://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear3/prog_index.m3u8"; + return "https://pointshow.oss-cn-hangzhou.aliyuncs.com/McTk51586843620689.mp4"; } } diff --git a/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java b/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java index 204fd298a..9b53fb0d7 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java @@ -28,9 +28,14 @@ import androidx.media3.exoplayer.ExoPlayer; import androidx.media3.exoplayer.source.MediaSource; import androidx.media3.exoplayer.source.MergingMediaSource; -import androidx.media3.exoplayer.source.SingleSampleMediaSource; +import androidx.media3.exoplayer.source.ProgressiveMediaSource; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter; +import androidx.media3.extractor.Extractor; +import androidx.media3.extractor.ExtractorsFactory; +import androidx.media3.extractor.text.DefaultSubtitleParserFactory; +import androidx.media3.extractor.text.SubtitleExtractor; +import androidx.media3.extractor.text.SubtitleParser; public class GSYExoSubTitlePlayer extends IjkExo2MediaPlayer { @@ -110,31 +115,40 @@ public void run() { 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_MEDIA3_CUES) - .setSelectionFlags(C.SELECTION_FLAG_FORCED) - /// 如果出现字幕不显示,可以通过修改这个语音去对应, - // 这个问题在内部的 selectTextTrack 时,TextTrackScore 通过 getFormatLanguageScore 方法判断语言获取匹配不上 - // 就会不出现字幕 - .setLanguage("zh-cn") - .build(); - - MediaItem.SubtitleConfiguration subtitle = new MediaItem.SubtitleConfiguration.Builder(subTitle) - .setMimeType(checkNotNull(textFormat.sampleMimeType)) - .setLanguage( textFormat.language) - .setSelectionFlags(textFormat.selectionFlags).build(); - - DefaultHttpDataSource.Factory factory = new DefaultHttpDataSource.Factory() - .setAllowCrossProtocolRedirects(true) - .setConnectTimeoutMs(50000) - .setReadTimeoutMs(50000) - .setTransferListener( new DefaultBandwidthMeter.Builder(mAppContext).build()); - - MediaSource textMediaSource = new SingleSampleMediaSource.Factory(new DefaultDataSource.Factory(mAppContext, - factory)) - .createMediaSource(subtitle, C.TIME_UNSET); - return textMediaSource; + Format format = new Format.Builder() + /// 其他的比如 text/x-ssa ,text/vtt,application/ttml+xml 等等 + .setSampleMimeType(MimeTypes.APPLICATION_SUBRIP) + .setSelectionFlags(C.SELECTION_FLAG_FORCED) + /// 如果出现字幕不显示,可以通过修改这个语音去对应, + // 这个问题在内部的 selectTextTrack 时,TextTrackScore 通过 getFormatLanguageScore 方法判断语言获取匹配不上 + // 就会不出现字幕 + .setLanguage(null) + .build(); + + MediaItem.SubtitleConfiguration subtitle = new MediaItem.SubtitleConfiguration.Builder(subTitle) + .setMimeType(checkNotNull(format.sampleMimeType)) + .setLanguage(format.language) + .setSelectionFlags(format.selectionFlags).build(); + + DefaultHttpDataSource.Factory factory = new DefaultHttpDataSource.Factory() + .setAllowCrossProtocolRedirects(true) + .setConnectTimeoutMs(50000) + .setReadTimeoutMs(50000) + .setTransferListener(new DefaultBandwidthMeter.Builder(mAppContext).build()); + + SubtitleParser.Factory subtitleParserFactory = new DefaultSubtitleParserFactory(); + + ExtractorsFactory extractorsFactory = + () -> + new Extractor[]{ + new SubtitleExtractor(subtitleParserFactory.create(format), format) + }; + ProgressiveMediaSource.Factory progressiveMediaSourceFactory = + new ProgressiveMediaSource.Factory(new DefaultDataSource.Factory(mAppContext, + factory), extractorsFactory); + + return progressiveMediaSourceFactory.createMediaSource( + MediaItem.fromUri(subtitle.uri.toString())); }