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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With