I want to buffer multiple videos before it is played. I have created a list of exoplayer instance for each video url, and passed that instances to the playerView which is in different activity. I am not getting any error but the video is not playing at all. I am not sure is this the correct way to achieve the pre-buffering. Below is my method where I am creating an arrayList of player instance.
private void setExoPlayer(String videoName, String folderName) {
SimpleExoPlayer tutorial_player;
String separator = "/";
String user_lang = manager.getString("getSelectedLanguage");
String videoUrl = Constant.appVideosURL + folderName + separator + user_lang + separator + videoName + separator + "hls" + separator + videoName + ".m3u8";
Uri videoUri = Uri.parse(videoUrl);
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);
DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
/*
parameters to define buffer
DEFAULT_MIN_BUFFER_MS = 360000
DEFAULT_MAX_BUFFER_MS = 700000
Valores default do ExoPlayer2
DEFAULT_BUFFER_FOR_PLAYBACK_MS = 2500
DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000
*/
DefaultLoadControl.Builder loadControl = new DefaultLoadControl.Builder();
loadControl.setBufferDurationsMs(360000, 700000, 2500, 5000);
//Initialize the player
tutorial_player = ExoPlayerFactory.newSimpleInstance(mctx, trackSelector);
tutorial_player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT);
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory =
new DefaultDataSourceFactory(mctx, Util.getUserAgent(mctx, "SmartMirror"), bandwidthMeter);
// This is the MediaSource representing the media to be played.
MediaSource mediaSource = new HlsMediaSource(videoUri, dataSourceFactory, 1, null, null);
tutorial_player.prepare(mediaSource);
tutorial_player.setPlayWhenReady(true);
tutorial_player.addListener(new Player.EventListener() {
@Override
public void onPlayerError(ExoPlaybackException error) {
String errorString = null;
if (error.type == ExoPlaybackException.TYPE_RENDERER) {
Exception cause = error.getRendererException();
if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
// Special case for decoder initialization failures.
MediaCodecRenderer.DecoderInitializationException decoderInitializationException =
(MediaCodecRenderer.DecoderInitializationException) cause;
if (decoderInitializationException.decoderName == null) {
if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
errorString = "error querying decoder";
} else if (decoderInitializationException.secureDecoderRequired) {
errorString = "error_no_secure_decoder";
} else {
errorString = "error_no_decoder";
}
} else {
errorString = "error_instantiating_decoder";
}
}
}
}
});
player.add(tutorial_player);
}
Here in this method I am taking only one instance from the arrayList and setting in the player.
public void setVideoPlayerAndMirrorPosition(SimpleExoPlayer simpleExoPlayer) {
playerView.setPlayer(simpleExoPlayer);
simpleExoPlayer.setPlayWhenReady(true);
}
I want to know how we can achieve this pre-buffering of multiple videos.