Skip to content

Commit

Permalink
update demo exo
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Nov 23, 2020
1 parent d5e9529 commit 6bd68b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void setDataSource(List<String> uris, Map<String, String> headers, int in
}



/**
* 上一集
*/
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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;

}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 6bd68b5

Please sign in to comment.