Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exoplayer- automatic change of quality is not working (hls)

Tags:

i have little problem with exoplayer. almost everything works fine when i try to play video from hls stream. hls stream contains 3 different sets of chunklists each for different bandwidth.

but hls adaptive streaming is not working and player works only with one chunklist and with slow internet connection is this solution unusable.

source code:

 BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
 TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
 TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
 this.simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector);
 this.videoPlayer.setPlayer(this.simpleExoPlayer);

 DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this.getActivity(), Util.getUserAgent(this.getActivity(), "appName"));
 MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(hlsUrl));
 this.simpleExoPlayer.prepare(mediaSource);
 this.simpleExoPlayer.setPlayWhenReady(true);

i tried to implement MediaSourceEventListener too and onDownstreamFormatChanged is called only once in the moment of player initialization.

thanks for any advices

like image 819
jakub Avatar asked Jan 28 '18 18:01

jakub


1 Answers

The key here is you need to pass the same "bandwidthMeter" you passed in to AdaptiveTrackSelection.Factory to the dataSourceFactory too. Only after these changes the Exoplayer does adaptive streaming as expected.

String userAgent = "XYZPLAYER";
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, bandwidthMeter, httpDataSourceFactory);
like image 96
Mayank Nakrani Avatar answered Sep 22 '22 12:09

Mayank Nakrani