From 7fb273fa3c33db5def503be35a416446afbe983f Mon Sep 17 00:00:00 2001 From: Mike Wilcox Date: Fri, 10 Apr 2015 22:58:36 -0400 Subject: [PATCH] added attachListeners method which listens for end of playback and sends a notification --- RCTVideo.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/RCTVideo.m b/RCTVideo.m index b41f5cbc..d1fd8171 100644 --- a/RCTVideo.m +++ b/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];