Merge pull request #85 from rnplay/rn-0.10-customevents-fix
RN 0.10 compatibility: switch to returning an array from customDirectEventTypes
This commit is contained in:
commit
e22eae417d
@ -1,12 +1,5 @@
|
|||||||
#import "RCTView.h"
|
#import "RCTView.h"
|
||||||
|
|
||||||
extern NSString *const RNVideoEventLoaded;
|
|
||||||
extern NSString *const RNVideoEventLoading;
|
|
||||||
extern NSString *const RNVideoEventProgress;
|
|
||||||
extern NSString *const RNVideoEventSeek;
|
|
||||||
extern NSString *const RNVideoEventLoadingError;
|
|
||||||
extern NSString *const RNVideoEventEnd;
|
|
||||||
|
|
||||||
@class RCTEventDispatcher;
|
@class RCTEventDispatcher;
|
||||||
|
|
||||||
@interface RCTVideo : UIView
|
@interface RCTVideo : UIView
|
||||||
|
19
RCTVideo.m
19
RCTVideo.m
@ -5,13 +5,6 @@
|
|||||||
#import "UIView+React.h"
|
#import "UIView+React.h"
|
||||||
#import <AVFoundation/AVFoundation.h>
|
#import <AVFoundation/AVFoundation.h>
|
||||||
|
|
||||||
NSString *const RNVideoEventLoaded = @"videoLoaded";
|
|
||||||
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";
|
static NSString *const statusKeyPath = @"status";
|
||||||
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
|
static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp";
|
||||||
|
|
||||||
@ -101,7 +94,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_prevProgressUpdateTime == nil || (([_prevProgressUpdateTime timeIntervalSinceNow] * -1000.0) >= _progressUpdateInterval)) {
|
if (_prevProgressUpdateTime == nil || (([_prevProgressUpdateTime timeIntervalSinceNow] * -1000.0) >= _progressUpdateInterval)) {
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventProgress
|
[_eventDispatcher sendInputEventWithName:@"onVideoProgress"
|
||||||
body:@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(video.currentTime)],
|
body:@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(video.currentTime)],
|
||||||
@"playableDuration": [self calculatePlayableDuration],
|
@"playableDuration": [self calculatePlayableDuration],
|
||||||
@"target": self.reactTag}];
|
@"target": self.reactTag}];
|
||||||
@ -192,7 +185,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
[self.layer addSublayer:_playerLayer];
|
[self.layer addSublayer:_playerLayer];
|
||||||
self.layer.needsDisplayOnBoundsChange = YES;
|
self.layer.needsDisplayOnBoundsChange = YES;
|
||||||
|
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventLoading
|
[_eventDispatcher sendInputEventWithName:@"onVideoLoadStart"
|
||||||
body:@{@"src": @{
|
body:@{@"src": @{
|
||||||
@"uri": [source objectForKey:@"uri"],
|
@"uri": [source objectForKey:@"uri"],
|
||||||
@"type": [source objectForKey:@"type"],
|
@"type": [source objectForKey:@"type"],
|
||||||
@ -232,7 +225,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
duration = 0.0;
|
duration = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventLoaded
|
[_eventDispatcher sendInputEventWithName:@"onVideoLoad"
|
||||||
body:@{@"duration": [NSNumber numberWithFloat:duration],
|
body:@{@"duration": [NSNumber numberWithFloat:duration],
|
||||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
||||||
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
|
@"canPlayReverse": [NSNumber numberWithBool:_playerItem.canPlayReverse],
|
||||||
@ -247,7 +240,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
[self attachListeners];
|
[self attachListeners];
|
||||||
[self applyModifiers];
|
[self applyModifiers];
|
||||||
} else if(_playerItem.status == AVPlayerItemStatusFailed) {
|
} else if(_playerItem.status == AVPlayerItemStatusFailed) {
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventLoadingError
|
[_eventDispatcher sendInputEventWithName:@"onVideoError"
|
||||||
body:@{@"error": @{
|
body:@{@"error": @{
|
||||||
@"code": [NSNumber numberWithInteger: _playerItem.error.code],
|
@"code": [NSNumber numberWithInteger: _playerItem.error.code],
|
||||||
@"domain": _playerItem.error.domain},
|
@"domain": _playerItem.error.domain},
|
||||||
@ -275,7 +268,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
|
|
||||||
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
- (void)playerItemDidReachEnd:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventEnd body:@{@"target": self.reactTag}];
|
[_eventDispatcher sendInputEventWithName:@"onVideoEnd" body:@{@"target": self.reactTag}];
|
||||||
|
|
||||||
if (_repeat) {
|
if (_repeat) {
|
||||||
AVPlayerItem *item = [notification object];
|
AVPlayerItem *item = [notification object];
|
||||||
@ -320,7 +313,7 @@ static NSString *const playbackLikelyToKeepUpKeyPath = @"playbackLikelyToKeepUp"
|
|||||||
|
|
||||||
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
if (CMTimeCompare(current, cmSeekTime) != 0) {
|
||||||
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
[_player seekToTime:cmSeekTime toleranceBefore:tolerance toleranceAfter:tolerance completionHandler:^(BOOL finished) {
|
||||||
[_eventDispatcher sendInputEventWithName:RNVideoEventSeek
|
[_eventDispatcher sendInputEventWithName:@"onVideoSeek"
|
||||||
body:@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
body:@{@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(item.currentTime)],
|
||||||
@"seekTime": [NSNumber numberWithFloat:seekTime],
|
@"seekTime": [NSNumber numberWithFloat:seekTime],
|
||||||
@"target": self.reactTag}];
|
@"target": self.reactTag}];
|
||||||
|
@ -16,28 +16,16 @@ RCT_EXPORT_MODULE();
|
|||||||
|
|
||||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||||
|
|
||||||
- (NSDictionary *)customDirectEventTypes
|
- (NSArray *)customDirectEventTypes
|
||||||
{
|
{
|
||||||
return @{
|
return @[
|
||||||
RNVideoEventLoading: @{
|
@"onVideoLoadStart",
|
||||||
@"registrationName": @"onVideoLoadStart"
|
@"onVideoLoad",
|
||||||
},
|
@"onVideoError",
|
||||||
RNVideoEventLoaded: @{
|
@"onVideoProgress",
|
||||||
@"registrationName": @"onVideoLoad"
|
@"onVideoSeek",
|
||||||
},
|
@"onVideoEnd"
|
||||||
RNVideoEventLoadingError: @{
|
];
|
||||||
@"registrationName": @"onVideoError"
|
|
||||||
},
|
|
||||||
RNVideoEventProgress: @{
|
|
||||||
@"registrationName": @"onVideoProgress"
|
|
||||||
},
|
|
||||||
RNVideoEventSeek: @{
|
|
||||||
@"registrationName": @"onVideoSeek"
|
|
||||||
},
|
|
||||||
RNVideoEventEnd: @{
|
|
||||||
@"registrationName": @"onVideoEnd"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (dispatch_queue_t)methodQueue
|
- (dispatch_queue_t)methodQueue
|
||||||
|
Loading…
Reference in New Issue
Block a user