Fix setting of resizeMode and repeat when changing source

This commit is contained in:
Mark Burns 2015-06-16 17:07:50 +09:00 committed by Brent Vatne
parent ab802303f3
commit 9723f8849f

View File

@ -39,6 +39,8 @@ static NSString *const statusKeyPath = @"status";
float _rate; float _rate;
BOOL _muted; BOOL _muted;
BOOL _paused; BOOL _paused;
BOOL _repeat;
NSString * _resizeMode;
} }
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
@ -48,6 +50,8 @@ static NSString *const statusKeyPath = @"status";
_rate = 1.0; _rate = 1.0;
_volume = 1.0; _volume = 1.0;
_resizeMode = @"AVLayerVideoGravityResizeAspectFill";
_pendingSeek = false; _pendingSeek = false;
_pendingSeekTime = 0.0f; _pendingSeekTime = 0.0f;
_lastSeekTime = 0.0f; _lastSeekTime = 0.0f;
@ -156,6 +160,8 @@ static NSString *const statusKeyPath = @"status";
_playerLayer.frame = self.bounds; _playerLayer.frame = self.bounds;
_playerLayer.needsDisplayOnBoundsChange = YES; _playerLayer.needsDisplayOnBoundsChange = YES;
[self applyModifiers];
[self.layer addSublayer:_playerLayer]; [self.layer addSublayer:_playerLayer];
self.layer.needsDisplayOnBoundsChange = YES; self.layer.needsDisplayOnBoundsChange = YES;
@ -216,7 +222,7 @@ static NSString *const statusKeyPath = @"status";
} else if(_playerItem.status == AVPlayerItemStatusFailed) { } else if(_playerItem.status == AVPlayerItemStatusFailed) {
[_eventDispatcher sendInputEventWithName:RNVideoEventLoadingError body:@{ [_eventDispatcher sendInputEventWithName:RNVideoEventLoadingError body:@{
@"error": @{ @"error": @{
@"code": [NSNumber numberWithInt:_playerItem.error.code], @"code": [NSNumber numberWithInt: (int)_playerItem.error.code],
@"domain": _playerItem.error.domain @"domain": _playerItem.error.domain
}, },
@"target": self.reactTag @"target": self.reactTag
@ -248,6 +254,7 @@ static NSString *const statusKeyPath = @"status";
- (void)setResizeMode:(NSString*)mode - (void)setResizeMode:(NSString*)mode
{ {
_resizeMode = mode;
_playerLayer.videoGravity = mode; _playerLayer.videoGravity = mode;
} }
@ -327,6 +334,9 @@ static NSString *const statusKeyPath = @"status";
} }
[_player setRate:_rate]; [_player setRate:_rate];
[self setResizeMode:_resizeMode];
[self setRepeat:_repeat];
[self setPaused:_paused]; [self setPaused:_paused];
} }
@ -344,6 +354,8 @@ static NSString *const statusKeyPath = @"status";
} }
- (void)setRepeat:(BOOL)repeat { - (void)setRepeat:(BOOL)repeat {
_repeat = repeat;
if (repeat) { if (repeat) {
[self setRepeatEnabled]; [self setRepeatEnabled];
} else { } else {