Added onTimedMetadata callback for iOS player and Exoplayer (#487)
* added listener for timedMetadata event. * added callback in RCTVideo for the timed metadata * exposing onTimedMetadata to JS * added forgotten method declaration * returning array of string values * added metadata type to the array * added onMetadata method * overridden onMetadata method on exoplayer2 * added format of return value from onMetadata * added function reference in README file
This commit is contained in:
committed by
Matt Apperson
parent
07ac819a46
commit
d792427ce1
@@ -16,6 +16,7 @@
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoProgress;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoSeek;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoEnd;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onTimedMetadata;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillPresent;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerDidPresent;
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onVideoFullscreenPlayerWillDismiss;
|
||||
|
@@ -9,6 +9,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
||||
static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
|
||||
static NSString *const readyForDisplayKeyPath = @"readyForDisplay";
|
||||
static NSString *const playbackRate = @"rate";
|
||||
static NSString *const timedMetadata = @"timedMetadata";
|
||||
|
||||
@implementation RCTVideo
|
||||
{
|
||||
@@ -226,6 +227,7 @@ static NSString *const playbackRate = @"rate";
|
||||
[_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
|
||||
[_playerItem addObserver:self forKeyPath:playbackBufferEmptyKeyPath options:0 context:nil];
|
||||
[_playerItem addObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath options:0 context:nil];
|
||||
[_playerItem addObserver:self forKeyPath:timedMetadata options:NSKeyValueObservingOptionNew context:nil];
|
||||
_playerItemObserversSet = YES;
|
||||
}
|
||||
|
||||
@@ -238,6 +240,7 @@ static NSString *const playbackRate = @"rate";
|
||||
[_playerItem removeObserver:self forKeyPath:statusKeyPath];
|
||||
[_playerItem removeObserver:self forKeyPath:playbackBufferEmptyKeyPath];
|
||||
[_playerItem removeObserver:self forKeyPath:playbackLikelyToKeepUpKeyPath];
|
||||
[_playerItem removeObserver:self forKeyPath:timedMetadata];
|
||||
_playerItemObserversSet = NO;
|
||||
}
|
||||
}
|
||||
@@ -318,6 +321,34 @@ static NSString *const playbackRate = @"rate";
|
||||
{
|
||||
if (object == _playerItem) {
|
||||
|
||||
// When timeMetadata is read the event onTimedMetadata is triggered
|
||||
if ([keyPath isEqualToString: timedMetadata])
|
||||
{
|
||||
|
||||
|
||||
NSArray<AVMetadataItem *> *items = [change objectForKey:@"new"];
|
||||
if (items && ![items isEqual:[NSNull null]] && items.count > 0) {
|
||||
|
||||
NSMutableArray *array = [NSMutableArray new];
|
||||
for (AVMetadataItem *item in items) {
|
||||
|
||||
NSString *value = item.value;
|
||||
NSString *identifier = item.identifier;
|
||||
|
||||
if (![value isEqual: [NSNull null]]) {
|
||||
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:@[value, identifier] forKeys:@[@"value", @"identifier"]];
|
||||
|
||||
[array addObject:dictionary];
|
||||
}
|
||||
}
|
||||
|
||||
self.onTimedMetadata(@{
|
||||
@"target": self.reactTag,
|
||||
@"metadata": array
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if ([keyPath isEqualToString:statusKeyPath]) {
|
||||
// Handle player item status change.
|
||||
if (_playerItem.status == AVPlayerItemStatusReadyToPlay) {
|
||||
|
@@ -41,6 +41,7 @@ RCT_EXPORT_VIEW_PROPERTY(onVideoError, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
|
||||
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);
|
||||
|
Reference in New Issue
Block a user