added attachListeners method which listens for end of playback and sends a notification

This commit is contained in:
Mike Wilcox 2015-04-10 22:58:36 -04:00 committed by Brent Vatne
parent ef48193266
commit 7fb273fa3c

View File

@ -10,6 +10,7 @@ NSString *const RNVideoEventLoading = @"videoLoading";
NSString *const RNVideoEventProgress = @"videoProgress"; NSString *const RNVideoEventProgress = @"videoProgress";
NSString *const RNVideoEventSeek = @"videoSeek"; NSString *const RNVideoEventSeek = @"videoSeek";
NSString *const RNVideoEventLoadingError = @"videoLoadError"; NSString *const RNVideoEventLoadingError = @"videoLoadError";
NSString *const RNVideoEventEnd = @"videoEnd";
static NSString *const statusKeyPath = @"status"; static NSString *const statusKeyPath = @"status";
@ -84,6 +85,12 @@ static NSString *const statusKeyPath = @"status";
[_progressUpdateTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; [_progressUpdateTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
} }
- (void)notifyEnd: (NSNotification *)notification {
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{
@"target": self.reactTag
}];
}
#pragma mark - Player and source #pragma mark - Player and source
- (void)setSrc:(NSDictionary *)source { - (void)setSrc:(NSDictionary *)source {
@ -149,6 +156,7 @@ static NSString *const statusKeyPath = @"status";
}]; }];
[self startProgressTimer]; [self startProgressTimer];
[self attachListeners];
[_player play]; [_player play];
[self applyModifiers]; [self applyModifiers];
} else if(_playerItem.status == AVPlayerItemStatusFailed) { } 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 { - (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *item = [notification object]; AVPlayerItem *item = [notification object];
[item seekToTime:kCMTimeZero]; [item seekToTime:kCMTimeZero];