diff --git a/app/src/main/java/com/example/gsyvideoplayer/exo/GSYExo2MediaPlayer.java b/app/src/main/java/com/example/gsyvideoplayer/exo/GSYExo2MediaPlayer.java index 0d21d0a6d..14ec24a55 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/exo/GSYExo2MediaPlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/exo/GSYExo2MediaPlayer.java @@ -87,7 +87,6 @@ public void setDataSource(List uris, Map headers, int in } - /** * 上一集 */ @@ -173,7 +172,7 @@ public void next() { int nextWindowIndex = mInternalPlayer.getNextWindowIndex(); if (nextWindowIndex != C.INDEX_UNSET) { mInternalPlayer.seekTo(nextWindowIndex, C.TIME_UNSET); - } else if (timeline.getWindow(windowIndex, window, false).isDynamic) { + } else if (timeline.getWindow(windowIndex, window).isDynamic) { mInternalPlayer.seekTo(windowIndex, C.TIME_UNSET); } } 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 dbd37943c..1c22041b7 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java +++ b/app/src/main/java/com/example/gsyvideoplayer/exosubtitle/GSYExoSubTitlePlayer.java @@ -9,6 +9,7 @@ import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MergingMediaSource; @@ -25,6 +26,8 @@ import tv.danmaku.ijk.media.exo2.IjkExo2MediaPlayer; import tv.danmaku.ijk.media.exo2.demo.EventLogger; +import static com.google.android.exoplayer2.util.Assertions.checkNotNull; + public class GSYExoSubTitlePlayer extends IjkExo2MediaPlayer { private String mSubTitile; @@ -88,7 +91,13 @@ public void run() { public MediaSource getTextSource(Uri subTitle) { //todo C.SELECTION_FLAG_AUTOSELECT language MimeTypes - Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, C.SELECTION_FLAG_FORCED, "en"); + Format textFormat = new Format.Builder() + .setSampleMimeType(MimeTypes.APPLICATION_SUBRIP) + .setSelectionFlags(C.SELECTION_FLAG_FORCED) + .setLanguage("en").build(); + + MediaItem.Subtitle subtitle = new MediaItem.Subtitle( + subTitle, checkNotNull(textFormat.sampleMimeType), textFormat.language, textFormat.selectionFlags); DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory(Util.getUserAgent(mAppContext, "GSYExoSubTitlePlayer"), new DefaultBandwidthMeter.Builder(mAppContext).build(), @@ -97,7 +106,7 @@ public MediaSource getTextSource(Uri subTitle) { MediaSource textMediaSource = new SingleSampleMediaSource.Factory(new DefaultDataSourceFactory(mAppContext, null, factory)) - .createMediaSource(subTitle, textFormat, C.TIME_UNSET); + .createMediaSource(subtitle, C.TIME_UNSET); return textMediaSource; } @@ -120,13 +129,13 @@ public void setTextOutput(TextOutput textOutput) { } public void addTextOutputPlaying(TextOutput textOutput) { - if(mInternalPlayer != null) { + if (mInternalPlayer != null) { mInternalPlayer.addTextOutput(textOutput); } } public void removeTextOutput(TextOutput textOutput) { - if(mInternalPlayer != null) { + if (mInternalPlayer != null) { mInternalPlayer.removeTextOutput(textOutput); } }