Fix attachListeners method's threading issue & other notification handling issues
This commit is contained in:
parent
17595f975b
commit
44b17119dd
42
RCTVideo.m
42
RCTVideo.m
@ -120,13 +120,6 @@ 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
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)addPlayerItemObserver
|
- (void)addPlayerItemObserver
|
||||||
{
|
{
|
||||||
[_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
|
[_playerItem addObserver:self forKeyPath:statusKeyPath options:0 context:nil];
|
||||||
@ -237,19 +230,25 @@ static NSString *const statusKeyPath = @"status";
|
|||||||
|
|
||||||
- (void)attachListeners
|
- (void)attachListeners
|
||||||
{
|
{
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
// listen for end of file
|
// listen for end of file
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(notifyEnd:)
|
selector:@selector(playerItemDidEnd:)
|
||||||
name:AVPlayerItemDidPlayToEndTimeNotification
|
name:AVPlayerItemDidPlayToEndTimeNotification
|
||||||
object:[_player currentItem]];
|
object:[_player currentItem]];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
- (void)playerItemDidEnd:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
|
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{
|
||||||
|
@"target": self.reactTag
|
||||||
|
}];
|
||||||
|
if (_repeat) {
|
||||||
AVPlayerItem *item = [notification object];
|
AVPlayerItem *item = [notification object];
|
||||||
[item seekToTime:kCMTimeZero];
|
[item seekToTime:kCMTimeZero];
|
||||||
[self applyModifiers];
|
[self applyModifiers];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Prop setters
|
#pragma mark - Prop setters
|
||||||
@ -342,27 +341,8 @@ static NSString *const statusKeyPath = @"status";
|
|||||||
[self setPaused:_paused];
|
[self setPaused:_paused];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRepeatEnabled
|
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
||||||
selector:@selector(playerItemDidReachEnd:)
|
|
||||||
name:AVPlayerItemDidPlayToEndTimeNotification
|
|
||||||
object:[_player currentItem]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setRepeatDisabled
|
|
||||||
{
|
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setRepeat:(BOOL)repeat {
|
- (void)setRepeat:(BOOL)repeat {
|
||||||
_repeat = repeat;
|
_repeat = repeat;
|
||||||
|
|
||||||
if (repeat) {
|
|
||||||
[self setRepeatEnabled];
|
|
||||||
} else {
|
|
||||||
[self setRepeatDisabled];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - React View Management
|
#pragma mark - React View Management
|
||||||
|
Loading…
Reference in New Issue
Block a user