From 618722515d737fab7fe03dce0b60a0b5c7fa149f Mon Sep 17 00:00:00 2001 From: Shane Mckenna Date: Wed, 12 Jan 2022 16:16:03 +0000 Subject: [PATCH 1/2] Add getPlayerAccessLogs, return playerAccessLogs in onVideoProgress --- ios/Video/RCTVideo.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 5021f95eae..5aba237fdc 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -290,6 +290,7 @@ - (void)sendProgressUpdate @"currentPlaybackTime": [NSNumber numberWithLongLong:[@(floor([currentPlaybackTime timeIntervalSince1970] * 1000)) longLongValue]], @"target": self.reactTag, @"seekableDuration": [self calculateSeekableDuration], + @"playerAccessLogs": [self getPlayerAccessLogs], }); } } @@ -1336,6 +1337,22 @@ - (NSArray *)getTextTrackInfo return textTracks; } +- (NSArray *)getPlayerAccessLogs +{ + AVPlayerItem *video = [_player currentItem]; + NSMutableArray *playerAccessLogs = [[NSMutableArray alloc] init]; + + for (AVPlayerItemAccessLogEvent *event in [[video accessLog] events] ) { + NSDictionary *accessLog = @{ + @"uri": [event URI], + @"segmentsDownloadedDuration": @([event segmentsDownloadedDuration]), + @"durationWatched": @([event durationWatched]) + }; + [playerAccessLogs addObject:accessLog]; + } + return playerAccessLogs; +} + - (BOOL)getFullscreen { return _fullscreenPlayerPresented; From 2327d253578dd92db7dd36756c2b928944c87359 Mon Sep 17 00:00:00 2001 From: Shane Mckenna Date: Thu, 27 Jan 2022 15:17:13 -0800 Subject: [PATCH 2/2] Update onVideoProgress with codec information --- ios/Video/RCTVideo.m | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index 5aba237fdc..c8014a9b2a 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -291,6 +291,7 @@ - (void)sendProgressUpdate @"target": self.reactTag, @"seekableDuration": [self calculateSeekableDuration], @"playerAccessLogs": [self getPlayerAccessLogs], + @"codecs": [self getEnabledTrackCodecs], }); } } @@ -1353,6 +1354,49 @@ - (NSArray *)getPlayerAccessLogs return playerAccessLogs; } +- (NSString *)mediaFormatWithFormatDescriptions:(NSArray *)formatDescriptions { + NSMutableString *format = [[NSMutableString alloc] init]; + for (int i = 0; i < formatDescriptions.count; i++) { + CMFormatDescriptionRef desc = + (__bridge CMFormatDescriptionRef)formatDescriptions[i]; + NSString *type = FourCCString(CMFormatDescriptionGetMediaType(desc)); + NSString *subType = FourCCString(CMFormatDescriptionGetMediaSubType(desc)); + [format appendFormat:@"%@/%@", type, subType]; + if (i < formatDescriptions.count - 1) { + [format appendString:@","]; + } + } + return format; +} + +static NSString * FourCCString(FourCharCode code) { + NSString *result = [NSString stringWithFormat:@"%c%c%c%c", + (code >> 24) & 0xff, + (code >> 16) & 0xff, + (code >> 8) & 0xff, + code & 0xff]; + NSCharacterSet *characterSet = [NSCharacterSet whitespaceCharacterSet]; + return [result stringByTrimmingCharactersInSet:characterSet]; +} + + - (NSArray *)getEnabledTrackCodecs + { + AVPlayerItem *video = [_player currentItem]; + NSMutableArray *codecs = [[NSMutableArray alloc] init]; + + for (AVPlayerItemTrack *track in video.tracks ) { + if(track.enabled){ + NSArray *formatDescriptions = track.assetTrack.formatDescriptions; + NSString *formats = [self mediaFormatWithFormatDescriptions:formatDescriptions]; + [codecs addObject:formats]; + } + } + + return codecs; + } + + + - (BOOL)getFullscreen { return _fullscreenPlayerPresented;