да, вам нужно создать несколько (8) экземпляров exoplayer, вы не можете сделать это с одним экземпляром
вот мой код,
private void initPlayer() {
if (player == null) {
trackSelectorParameters = new DefaultTrackSelector.ParametersBuilder().build();
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(trackSelectionFactory);
trackSelector.setParameters(trackSelectorParameters);
RenderersFactory renderersFactory = ((MyAppApplication) context.getApplicationContext()).buildRenderersFactory();
player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector);
player.setPlayWhenReady(true);
//to print log of ExoPlayer
//player.addAnalyticsListener(new EventLogger(trackSelector));
progressiveMediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
}
}
используйте приведенный выше код дляинициализируйте exoplayer и вызовите этот метод, чтобы добавить все 8 URI
s для воспроизведения одновременно
public void startPlaying(Uri uri) {
if (player == null) initPlayer();
MediaSource mediaSource = progressiveMediaSourceFactory.createMediaSource(uri);
player.prepare(mediaSource, true, false);
}
вот ссылка на Github - https://github.com/google/ExoPlayer
использование exoplayer-core
библиотека
для этого я хотел бы предложить вам создать отдельный класс для ExoPlayer для инициализации, запуска, остановки и тому подобное ...
public class MyAppExoPlayer {
private final Context context;
private DataSource.Factory dataSourceFactory;
private SimpleExoPlayer player;
private DefaultTrackSelector trackSelector;
private DefaultTrackSelector.Parameters trackSelectorParameters;
private ProgressiveMediaSource.Factory progressiveMediaSourceFactory;
private ConcatenatingMediaSource concatenatingMediaSource;
private int currentMediaPlayerIndex = 0;
public MyAppExoPlayer(Context context) {
this.context = context;
dataSourceFactory = ((MyAppApplication) context.getApplicationContext()).buildDataSourceFactory();
initPlayer();
}
private void initPlayer() {
if (player == null) {
trackSelectorParameters = new DefaultTrackSelector.ParametersBuilder().build();
TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory();
trackSelector = new DefaultTrackSelector(trackSelectionFactory);
trackSelector.setParameters(trackSelectorParameters);
RenderersFactory renderersFactory = ((MyAppApplication) context.getApplicationContext()).buildRenderersFactory();
player = ExoPlayerFactory.newSimpleInstance(context, renderersFactory, trackSelector);
player.setPlayWhenReady(true);
//to print log of ExoPlayer
//player.addAnalyticsListener(new EventLogger(trackSelector));
progressiveMediaSourceFactory = new ProgressiveMediaSource.Factory(dataSourceFactory);
}
concatenatingMediaSource = new ConcatenatingMediaSource();
}
public void startPlaying(Uri uri) {
if (player == null) initPlayer();
MediaSource mediaSource = progressiveMediaSourceFactory.createMediaSource(uri);
player.prepare(mediaSource, true, false);
}
public void addToQ(Uri uri) {
if (player == null) return;
MediaSource mediaSource = progressiveMediaSourceFactory.createMediaSource(uri);
concatenatingMediaSource.addMediaSource(mediaSource);
}
public void stopPlaying() {
if (player != null) {
player.stop(true);
concatenatingMediaSource.clear();
}
}
public long getCurrentPosition() {
if (player != null)
return player.getCurrentPosition();
return 0;
}
public void releasePlayer() {
if (player != null) {
if (trackSelector != null) {
trackSelectorParameters = trackSelector.getParameters();
}
player.release();
player = null;
trackSelector = null;
}
}
}
Теперь создайте 8 экземпляров, если MyAppExoPlayer
и звоните startPlaying()