Skip to content

Commit

Permalink
update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Nov 20, 2024
1 parent 12d1207 commit afdb955
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.media3.exoplayer.DefaultRenderersFactory;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.source.ConcatenatingMediaSource;
import androidx.media3.exoplayer.source.ConcatenatingMediaSource2;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector;

Expand Down Expand Up @@ -84,6 +85,18 @@ public void setDataSource(List<String> uris, Map<String, String> headers, int in
}
playIndex = index;
mMediaSource = concatenatedSource;


/// ConcatenatingMediaSource2 是把多个视频拼成一个播放,时间轴只有一个
// ConcatenatingMediaSource2.Builder mediaSourceBuilder =
// new ConcatenatingMediaSource2.Builder().useDefaultMediaSourceFactory(mAppContext);
//
// for (String uri : uris) {
// MediaSource mediaSource = mExoHelper.getMediaSource(uri, isPreview, cache, false, mCacheDir, getOverrideExtension());
// mediaSourceBuilder.add(mediaSource, 0);
// }
// playIndex = index;
// mMediaSource = mediaSourceBuilder.build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.Looper;


import java.util.ArrayList;
import java.util.List;

import tv.danmaku.ijk.media.exo2.IjkExo2MediaPlayer;
Expand Down Expand Up @@ -101,11 +102,32 @@ public void run() {
if (mSurface != null)
mInternalPlayer.setVideoSurface(mSurface);


///其实如果你没什么特色需求,可以直接用下面这种方式
// List<MediaItem.SubtitleConfiguration> list = new ArrayList<>();
// if (mSubTitile != null) {
// MediaItem.SubtitleConfiguration subtitle
// = new MediaItem.SubtitleConfiguration.Builder(Uri.parse(mSubTitile))
// .setMimeType(MimeTypes.APPLICATION_SUBRIP)
// .setLanguage(null)
// .setSelectionFlags(C.SELECTION_FLAG_FORCED)
// .build();
// list.add(subtitle);
// }
// MediaItem mediaItem = new MediaItem.Builder()
// .setUri(mDataSource).
// setSubtitleConfigurations(list).build();
// mInternalPlayer.setMediaItem(mediaItem);

if (mSubTitile != null) {
MediaSource textMediaSource = getTextSource(Uri.parse(mSubTitile));
mMediaSource = new MergingMediaSource(mMediaSource, textMediaSource);
}
mInternalPlayer.setMediaSource(mMediaSource);




mInternalPlayer.prepare();
mInternalPlayer.setPlayWhenReady(false);
}
Expand Down

0 comments on commit afdb955

Please sign in to comment.