对于http streaming,更新buffer进度的处理在AwesomePlayer::onBufferingUpdate()函数中,首先判断 mCachedSource != NULL,即是http://流媒体的情况下,通过getBitrate(&bitrate)函数取得bitrate,然后计算出buffer的 进度,通过notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage)发消息,在MediaPlayer.cpp类对应MediaPlayer::notify函数接收到 MEDIA_BUFFERING_UPDATE消息,然后在应用层通过注册MediaPlayer的 setOnBufferingUpdateListener监听,接收到MEDIA_BUFFERING_UPDATE消息,即可以获得buffer更新 的进度值percent。
1.AwesomePlayer::onBufferingUpdate()函数
计算buffer更新的percent
[cpp] view plaincopy
- if (getBitrate(&bitrate)) {
- LOGV("onBufferingUpdate: bitrate: %lld", bitrate);
- size_t lowWaterThreshold = (size_t) ((bitrate * kLowWaterMarkUs
- * (1.0f + kThresholdPaddingFactor)) / 8000000ll);
- size_t highWaterThreshold = (size_t) ((bitrate
- * kHighWaterMarkUs * (1.0f + kThresholdPaddingFactor))
- / 8000000ll);
- mCachedSource->setThresholds(lowWaterThreshold,
- highWaterThreshold);
- size_t cachedSize = mCachedSource->cachedSize();
- int64_t cachedDurationUs = cachedSize * 8000000ll / bitrate;
- int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
- if (percentage > 100) {