I'm trying to get the bandwidth using getBitRateEstimate but it keeps returning -1 :
(I think the issue has something to do with not providing the meter to the DataSourceFactory, but I can't figure out how to do it)
Here is the code :
private void createView(Context context) {
LayoutParams layoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
playerView = new PlayerView(getContext());
bandwidthMeter = new DefaultBandwidthMeter();
playerView.setLayoutParams(layoutParams);
myContext = context;
addView(playerView, 0, layoutParams);
}
public void initializeMediaPlayer() {
/**
* Create Simple Exoplayer Player
*/
if(player == null) {
//bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new
DefaultTrackSelector(videoTrackSelectionFactory);
DefaultAllocator defaultAllocator = new
DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
LoadControl loadControl = new
DefaultLoadControl(defaultAllocator, 1450, 3000, 1000, 1000,
C.LENGTH_UNSET, false);
RenderersFactory renderersFactory = new DefaultRenderersFactory(myContext);
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
playerView.setUseController(false);
playerView.setPlayer(player);
}
/**
* Create RTMP Data Source
*/
rtmpDataSourceFactory = new RtmpDataSourceFactory();
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource videoSource = new ExtractorMediaSource.Factory(rtmpDataSourceFactory).createMediaSource(Uri.parse(source));
//MediaSource videoSource = new ExtractorMediaSource(Uri.parse("rtmp://35.231.80.114/live/myStream"),
// rtmpDataSourceFactory, extractorsFactory, null, null);
player.addListener(new PlayerEventListener());
player.setPlayWhenReady(true);
player.seekToDefaultPosition();
player.prepare(videoSource);
}