我需要从exoplayer中找到流式视频比特率,但是此代码似乎并未显示真实比特率
bitrateEstimate = bandwidthMeter.bitrateEstimate
最佳答案
Exoplayer提供BandwidthMeter事件here的侦听器。
您可以在代码中使用它,例如:
Handler handler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(MainActivity.this).build();
bandwidthMeter.addEventListener(handler, new BandwidthMeter.EventListener() {
@Override
public void onBandwidthSample(int elapsedMs, long bytesTransferred, long bitrateEstimate) {
Log.d(TAG, "elapsedMs: " + elapsedMs);
Log.d(TAG, "bytes transferred: " + bytesTransferred);
Log.d(TAG, "Average bitrate (bps) = " + (double) (bytesTransferred * 8) / (elapsedMs / 1000));
}
});