added attachListeners method which listens for end of playback and sends a notification
This commit is contained in:
parent
ef48193266
commit
7fb273fa3c
18
RCTVideo.m
18
RCTVideo.m
@ -10,6 +10,7 @@ NSString *const RNVideoEventLoading = @"videoLoading";
|
||||
NSString *const RNVideoEventProgress = @"videoProgress";
|
||||
NSString *const RNVideoEventSeek = @"videoSeek";
|
||||
NSString *const RNVideoEventLoadingError = @"videoLoadError";
|
||||
NSString *const RNVideoEventEnd = @"videoEnd";
|
||||
|
||||
static NSString *const statusKeyPath = @"status";
|
||||
|
||||
@ -84,6 +85,12 @@ static NSString *const statusKeyPath = @"status";
|
||||
[_progressUpdateTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
- (void)notifyEnd: (NSNotification *)notification {
|
||||
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{
|
||||
@"target": self.reactTag
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Player and source
|
||||
|
||||
- (void)setSrc:(NSDictionary *)source {
|
||||
@ -149,6 +156,7 @@ static NSString *const statusKeyPath = @"status";
|
||||
}];
|
||||
|
||||
[self startProgressTimer];
|
||||
[self attachListeners];
|
||||
[_player play];
|
||||
[self applyModifiers];
|
||||
} else if(_playerItem.status == AVPlayerItemStatusFailed) {
|
||||
@ -165,6 +173,16 @@ static NSString *const statusKeyPath = @"status";
|
||||
}
|
||||
}
|
||||
|
||||
- (void)attachListeners {
|
||||
|
||||
// listen for end of file
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(notifyEnd:)
|
||||
name:AVPlayerItemDidPlayToEndTimeNotification
|
||||
object:[_player currentItem]];
|
||||
|
||||
}
|
||||
|
||||
- (void)playerItemDidReachEnd:(NSNotification *)notification {
|
||||
AVPlayerItem *item = [notification object];
|
||||
[item seekToTime:kCMTimeZero];
|
||||
|
Loading…
Reference in New Issue
Block a user