I am using Exoplayer in my Android app for streaming hls audio, I am trying to play adaptive stream using my master HLS playlist which contains various variant of the same audio track but in different bitrate as per suitable available network bandwidth.
But what i have seen, the Exoplayer starts playing with the initial variant in the master playlist, and then immediately moves to the highest available bitrate variant of audio, every time. It doesn't uses any of the other bitrate even if I have changed my network to 2G, 3G or any other lower bandwidth, it doesn't adapts to lower bitrate in any case and follows the above pattern. It will keep buffering for very long, but never use any lower track variant as per the bandwidth.
Here's the code of my Exoplayer implementation -
private void initialisePlayer(){
if(exoPlayer == null) {
AdaptiveTrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory();
TrackSelector trackSelector = new DefaultTrackSelector(this, videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
exoPlayer = new ExoPlayer.Builder(getApplicationContext())
.setTrackSelector(trackSelector).setLoadControl(loadControl).build();
exoPlayer.addListener(listener);
exoPlayer.setAudioAttributes(audioAttributes, /* handleAudioFocus= */ true);
exoPlayer.setHandleAudioBecomingNoisy(true);
}
}
private void playAudio(){
DefaultBandwidthMeter bandwidthMeter = DefaultBandwidthMeter.getSingletonInstance(this);
DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this).setTransferListener(bandwidthMeter);
HlsMediaSource audioSource = HlsMediaSource.Factory(dataSourceFactory)
.setLoadErrorHandlingPolicy(new CustomPolicy())
.createMediaSource(MediaItem.fromUri("my-hls-master-url"));
exoPlayer.setMediaSource(audioSource);
exoPlayer.prepare();
exoPlayer.setPlayWhenReady(true);
}
I am using -
implementation 'androidx.media3:media3-exoplayer:1.1.1'
implementation "androidx.media3:media3-exoplayer-hls:1.1.1"
I have my master playlist as like -
#EXT-X-VERSION:4
# Audio Renditions
#EXT-X-STREAM-INF:BANDWIDTH=54000,CODECS="mp4a.40.5"
songs54/audio.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=84000,CODECS="mp4a.40.5"
songs84/audio.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=126000,CODECS="mp4a.40.2"
songs126/audio.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=160000,CODECS="mp4a.40.5"
songs160/audio.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=320000,CODECS="mp4a.40.2"
songs320/audio.m3u8
I have been trying to fix this from last 2 days, any help will be really appreciated.