diff --git a/ios/Video/RCTVideo.m b/ios/Video/RCTVideo.m index b2f661cbb3..3a57c61593 100644 --- a/ios/Video/RCTVideo.m +++ b/ios/Video/RCTVideo.m @@ -319,6 +319,8 @@ - (void)sendProgressUpdate @"currentPlaybackTime": [NSNumber numberWithLongLong:[@(floor([currentPlaybackTime timeIntervalSince1970] * 1000)) longLongValue]], @"target": self.reactTag, @"seekableDuration": [self calculateSeekableDuration], + @"playerAccessLogs": [self getPlayerAccessLogs], + @"codecs": [self getEnabledTrackCodecs], }); } } @@ -1369,6 +1371,65 @@ - (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; +} + +- (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;