From b256f2d4d81b8b4c0288fd3e466af50838574fb2 Mon Sep 17 00:00:00 2001 From: sridhar Date: Wed, 19 Sep 2018 17:58:49 +0530 Subject: [PATCH] IOS bandwidth reporting IOS bandwidth reporting --- ios/RCTVideo.h | 1 + ios/RCTVideo.m | 6 ++++-- ios/RCTVideoManager.m | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ios/RCTVideo.h b/ios/RCTVideo.h index 1c471236..a63747ca 100644 --- a/ios/RCTVideo.h +++ b/ios/RCTVideo.h @@ -14,6 +14,7 @@ @property (nonatomic, copy) RCTBubblingEventBlock onVideoBuffer; @property (nonatomic, copy) RCTBubblingEventBlock onVideoError; @property (nonatomic, copy) RCTBubblingEventBlock onVideoProgress; +@property (nonatomic, copy) RCTBubblingEventBlock onBandwidthUpdate; @property (nonatomic, copy) RCTBubblingEventBlock onVideoSeek; @property (nonatomic, copy) RCTBubblingEventBlock onVideoEnd; @property (nonatomic, copy) RCTBubblingEventBlock onTimedMetadata; diff --git a/ios/RCTVideo.m b/ios/RCTVideo.m index 2d5030ca..a00fe7c8 100644 --- a/ios/RCTVideo.m +++ b/ios/RCTVideo.m @@ -592,8 +592,10 @@ static int const RCTVideoUnset = -1; - (void)handleAVPlayerAccess:(NSNotification *)notification { AVPlayerItemAccessLog *accessLog = [((AVPlayerItem *)notification.object) accessLog]; AVPlayerItemAccessLogEvent *lastEvent = accessLog.events.lastObject; - float lastEventNumber = lastEvent.indicatedBitrate; - RCTLog(@"Switch indicatedBitrate from: %f to: %f", lastEvent.observedBitrate, lastEvent.indicatedBitrate); + + if (self.onBandwidthUpdate) { + self.onBandwidthUpdate(@{@"bitrateEstimate": [NSNumber numberWithFloat:(lastEvent.observedBitrate/1000)]}); + } } - (void)playbackStalled:(NSNotification *)notification diff --git a/ios/RCTVideoManager.m b/ios/RCTVideoManager.m index e0e0162e..c3dfa4c2 100644 --- a/ios/RCTVideoManager.m +++ b/ios/RCTVideoManager.m @@ -44,6 +44,7 @@ RCT_EXPORT_VIEW_PROPERTY(onVideoLoad, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoBuffer, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoError, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTBubblingEventBlock); +RCT_EXPORT_VIEW_PROPERTY(onBandwidthUpdate, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock);