removed play button

* Removed play button from ASVideoNode
* Removed play button tests
* added some checks in ASVideoPlayerNode
* added new delegate method for time formats
This commit is contained in:
Erekle
2016-05-13 00:46:55 +04:00
parent ae5440ad11
commit 98c451118b
5 changed files with 34 additions and 85 deletions

View File

@@ -58,9 +58,6 @@ NS_ASSUME_NONNULL_BEGIN
//! Defaults to AVLayerVideoGravityResizeAspect //! Defaults to AVLayerVideoGravityResizeAspect
@property (atomic) NSString *gravity; @property (atomic) NSString *gravity;
//! Defaults to an ASDefaultPlayButton instance.
@property (nullable, atomic) ASButtonNode *playButton;
@property (nullable, atomic, weak, readwrite) id<ASVideoNodeDelegate> delegate; @property (nullable, atomic, weak, readwrite) id<ASVideoNodeDelegate> delegate;
@end @end

View File

@@ -64,7 +64,6 @@ static NSString * const kStatus = @"status";
ASImageNode *_placeholderImageNode; // TODO: Make ASVideoNode an ASImageNode subclass; remove this. ASImageNode *_placeholderImageNode; // TODO: Make ASVideoNode an ASImageNode subclass; remove this.
ASButtonNode *_playButtonNode;
ASDisplayNode *_playerNode; ASDisplayNode *_playerNode;
ASDisplayNode *_spinnerNode; ASDisplayNode *_spinnerNode;
NSString *_gravity; NSString *_gravity;
@@ -84,7 +83,6 @@ static NSString * const kStatus = @"status";
return nil; return nil;
} }
self.playButton = [[ASDefaultPlayButton alloc] init];
self.gravity = AVLayerVideoGravityResizeAspect; self.gravity = AVLayerVideoGravityResizeAspect;
_periodicTimeObserverTimescale = 10000; _periodicTimeObserverTimescale = 10000;
[self addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside]; [self addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
@@ -201,10 +199,7 @@ static NSString * const kStatus = @"status";
// Stretch out play button, placeholder image player node to the max size // Stretch out play button, placeholder image player node to the max size
NSMutableArray *children = [NSMutableArray array]; NSMutableArray *children = [NSMutableArray array];
if (_playButtonNode) {
_playButtonNode.preferredFrameSize = maxSize;
[children addObject:_playButtonNode];
}
if (_placeholderImageNode) { if (_placeholderImageNode) {
_placeholderImageNode.preferredFrameSize = maxSize; _placeholderImageNode.preferredFrameSize = maxSize;
[children addObject:_placeholderImageNode]; [children addObject:_placeholderImageNode];
@@ -224,18 +219,6 @@ static NSString * const kStatus = @"status";
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:children]; return [ASStaticLayoutSpec staticLayoutSpecWithChildren:children];
} }
- (void)layout
{
[super layout];
CGRect bounds = self.bounds;
ASDN::MutexLocker l(_videoLock);
CGFloat horizontalDiff = (CGRectGetWidth(bounds) - CGRectGetWidth(_playButtonNode.bounds))/2;
CGFloat verticalDiff = (CGRectGetHeight(bounds) - CGRectGetHeight(_playButtonNode.bounds))/2;
_playButtonNode.hitTestSlop = UIEdgeInsetsMake(-verticalDiff, -horizontalDiff, -verticalDiff, -horizontalDiff);
}
- (void)generatePlaceholderImage - (void)generatePlaceholderImage
{ {
ASVideoNode * __weak weakSelf = self; ASVideoNode * __weak weakSelf = self;
@@ -421,26 +404,6 @@ static NSString * const kStatus = @"status";
_playerState = playerState; _playerState = playerState;
} }
- (void)setPlayButton:(ASButtonNode *)playButton
{
ASDN::MutexLocker l(_videoLock);
[_playButtonNode removeTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[_playButtonNode removeFromSupernode];
_playButtonNode = playButton;
[_playButtonNode addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[self addSubnode:playButton];
[self setNeedsLayout];
}
- (ASButtonNode *)playButton
{
ASDN::MutexLocker l(_videoLock);
return _playButtonNode;
}
- (void)setAsset:(AVAsset *)asset - (void)setAsset:(AVAsset *)asset
{ {
ASDN::MutexLocker l(_videoLock); ASDN::MutexLocker l(_videoLock);
@@ -537,11 +500,8 @@ static NSString * const kStatus = @"status";
if (_playerNode == nil) { if (_playerNode == nil) {
_playerNode = [self constructPlayerNode]; _playerNode = [self constructPlayerNode];
if (_playButtonNode.supernode == self) {
[self insertSubnode:_playerNode belowSubnode:_playButtonNode];
} else {
[self addSubnode:_playerNode]; [self addSubnode:_playerNode];
}
[self setNeedsLayout]; [self setNeedsLayout];
} }
@@ -550,9 +510,6 @@ static NSString * const kStatus = @"status";
[_player play]; [_player play];
_shouldBePlaying = YES; _shouldBePlaying = YES;
[UIView animateWithDuration:0.15 animations:^{
_playButtonNode.alpha = 0.0;
}];
if (![self ready]) { if (![self ready]) {
[self showSpinner]; [self showSpinner];
} else { } else {
@@ -605,9 +562,6 @@ static NSString * const kStatus = @"status";
[_player pause]; [_player pause];
[self removeSpinner]; [self removeSpinner];
_shouldBePlaying = NO; _shouldBePlaying = NO;
[UIView animateWithDuration:0.15 animations:^{
_playButtonNode.alpha = 1.0;
}];
} }
- (BOOL)isPlaying - (BOOL)isPlaying
@@ -733,7 +687,6 @@ static NSString * const kStatus = @"status";
{ {
[_player removeTimeObserver:_timeObserver]; [_player removeTimeObserver:_timeObserver];
_timeObserver = nil; _timeObserver = nil;
[_playButtonNode removeTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[self removePlayerItemObservers:_currentPlayerItem]; [self removePlayerItemObservers:_currentPlayerItem];
} }

View File

@@ -66,6 +66,9 @@ NS_ASSUME_NONNULL_BEGIN
* @param timeLabelType * @param timeLabelType
*/ */
- (NSDictionary *)videoPlayerNodeTimeLabelAttributes:(ASVideoPlayerNode *)videoPlayerNode timeLabelType:(ASVideoPlayerNodeControlType)timeLabelType; - (NSDictionary *)videoPlayerNodeTimeLabelAttributes:(ASVideoPlayerNode *)videoPlayerNode timeLabelType:(ASVideoPlayerNodeControlType)timeLabelType;
- (NSString *)videoPlayerNode:(ASVideoPlayerNode *)videoPlayerNode
timeStringForTimeLabelType:(ASVideoPlayerNodeControlType)timeLabelType
forTime:(CMTime)time;
#pragma mark Scrubber delegate methods #pragma mark Scrubber delegate methods
- (UIColor *)videoPlayerNodeScrubberMaximumTrackTint:(ASVideoPlayerNode *)videoPlayer; - (UIColor *)videoPlayerNodeScrubberMaximumTrackTint:(ASVideoPlayerNode *)videoPlayer;

View File

@@ -23,6 +23,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
unsigned int delegateScrubberThumbTintColor:1; unsigned int delegateScrubberThumbTintColor:1;
unsigned int delegateScrubberThumbImage:1; unsigned int delegateScrubberThumbImage:1;
unsigned int delegateTimeLabelAttributes:1; unsigned int delegateTimeLabelAttributes:1;
unsigned int delegateTimeLabelAttributedString:1;
unsigned int delegateLayoutSpecForControls:1; unsigned int delegateLayoutSpecForControls:1;
unsigned int delegateVideoNodeDidPlayToTime:1; unsigned int delegateVideoNodeDidPlayToTime:1;
unsigned int delegateVideoNodeWillChangeState:1; unsigned int delegateVideoNodeWillChangeState:1;
@@ -176,12 +177,13 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
- (void)removeControls - (void)removeControls
{ {
// [_cachedControls enumerateObjectsUsingBlock:^(ASDisplayNode *_Nonnull node, NSUInteger idx, BOOL * _Nonnull stop) { NSArray *controls = [_cachedControls allValues];
// [node.view removeFromSuperview]; [controls enumerateObjectsUsingBlock:^(ASDisplayNode *_Nonnull node, NSUInteger idx, BOOL * _Nonnull stop) {
// [node removeFromSupernode]; [node.view removeFromSuperview];
// node = nil; [node removeFromSupernode];
// NSLog(@"%@",_playbackButtonNode); //node = nil;
// }]; NSLog(@"%@",_playbackButtonNode);
}];
} }
- (void)createPlaybackButton - (void)createPlaybackButton
@@ -272,13 +274,13 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
- (void)updateDurationTimeLabel - (void)updateDurationTimeLabel
{ {
NSString *formatedDuration = [self timeStringForCMTime:_duration]; NSString *formatedDuration = [self timeStringForCMTime:_duration forTimeLabelType:ASVideoPlayerNodeControlTypeDurationText];
_durationTextNode.attributedString = [self timeLabelAttributedStringForString:formatedDuration forControlType:ASVideoPlayerNodeControlTypeDurationText]; _durationTextNode.attributedString = [self timeLabelAttributedStringForString:formatedDuration forControlType:ASVideoPlayerNodeControlTypeDurationText];
} }
- (void)updateElapsedTimeLabel:(NSTimeInterval)seconds - (void)updateElapsedTimeLabel:(NSTimeInterval)seconds
{ {
NSString *formatedDuration = [self timeStringForCMTime:CMTimeMakeWithSeconds( seconds, _videoNode.periodicTimeObserverTimescale )]; NSString *formatedDuration = [self timeStringForCMTime:CMTimeMakeWithSeconds( seconds, _videoNode.periodicTimeObserverTimescale ) forTimeLabelType:ASVideoPlayerNodeControlTypeElapsedText];
_elapsedTextNode.attributedString = [self timeLabelAttributedStringForString:formatedDuration forControlType:ASVideoPlayerNodeControlTypeElapsedText]; _elapsedTextNode.attributedString = [self timeLabelAttributedStringForString:formatedDuration forControlType:ASVideoPlayerNodeControlTypeElapsedText];
} }
@@ -307,7 +309,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
[_delegate videoPlayerNode:self willChangeVideoNodeState:state toVideoNodeState:toState]; [_delegate videoPlayerNode:self willChangeVideoNodeState:state toVideoNodeState:toState];
} }
if (toState == ASVideoNodePlayerStateReadyToPlay) { if (toState == ASVideoNodePlayerStateReadyToPlay && _durationTextNode) {
_duration = _videoNode.currentItem.duration; _duration = _videoNode.currentItem.duration;
[self updateDurationTimeLabel]; [self updateDurationTimeLabel];
} }
@@ -334,8 +336,13 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
return; return;
} }
if (_elapsedTextNode) {
[self updateElapsedTimeLabel:second]; [self updateElapsedTimeLabel:second];
}
if (_scrubberNode) {
[(UISlider*)_scrubberNode.view setValue:(second/ CMTimeGetSeconds(_duration) ) animated:NO]; [(UISlider*)_scrubberNode.view setValue:(second/ CMTimeGetSeconds(_duration) ) animated:NO];
}
} }
- (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode - (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode
@@ -343,7 +350,6 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
if (_delegateFlags.delegateVideoNodePlaybackDidFinish) { if (_delegateFlags.delegateVideoNodePlaybackDidFinish) {
[_delegate videoPlayerNodePlaybackDidFinish:self]; [_delegate videoPlayerNodePlaybackDidFinish:self];
} }
//[self removeControls];
} }
#pragma mark - Actions #pragma mark - Actions
@@ -423,6 +429,7 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
} }
ASOverlayLayoutSpec *overlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_videoNode overlay:layoutSpec]; ASOverlayLayoutSpec *overlaySpec = [ASOverlayLayoutSpec overlayLayoutSpecWithChild:_videoNode overlay:layoutSpec];
overlaySpec.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(constrainedSize.max);
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[overlaySpec]]; return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[overlaySpec]];
} }
@@ -479,13 +486,17 @@ static void *ASVideoPlayerNodeContext = &ASVideoPlayerNodeContext;
_delegateFlags.delegateVideoNodeWillChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:willChangeVideoNodeState:toVideoNodeState:)]; _delegateFlags.delegateVideoNodeWillChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:willChangeVideoNodeState:toVideoNodeState:)];
_delegateFlags.delegateVideoNodePlaybackDidFinish = [_delegate respondsToSelector:@selector(videoPlayerNodePlaybackDidFinish:)]; _delegateFlags.delegateVideoNodePlaybackDidFinish = [_delegate respondsToSelector:@selector(videoPlayerNodePlaybackDidFinish:)];
_delegateFlags.delegateVideoNodeShouldChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:shouldChangeVideoNodeStateTo:)]; _delegateFlags.delegateVideoNodeShouldChangeState = [_delegate respondsToSelector:@selector(videoPlayerNode:shouldChangeVideoNodeStateTo:)];
_delegateFlags.delegateTimeLabelAttributedString = [_delegate respondsToSelector:@selector(videoPlayerNode:timeStringForTimeLabelType:forTime:)];
} }
} }
#pragma mark - Helpers #pragma mark - Helpers
- (NSString *)timeStringForCMTime:(CMTime)time - (NSString *)timeStringForCMTime:(CMTime)time forTimeLabelType:(ASVideoPlayerNodeControlType)type
{ {
//TODO: ask Max if delegate for this thing will be useful; if (_delegateFlags.delegateTimeLabelAttributedString) {
return [_delegate videoPlayerNode:self timeStringForTimeLabelType:type forTime:time];
}
NSUInteger dTotalSeconds = CMTimeGetSeconds(time); NSUInteger dTotalSeconds = CMTimeGetSeconds(time);
NSUInteger dHours = floor(dTotalSeconds / 3600); NSUInteger dHours = floor(dTotalSeconds / 3600);

View File

@@ -379,21 +379,6 @@
XCTAssertEqual(UIViewContentModeScaleAspectFill, _videoNode.placeholderImageNode.contentMode); XCTAssertEqual(UIViewContentModeScaleAspectFill, _videoNode.placeholderImageNode.contentMode);
} }
- (void)testChangingPlayButtonPerformsProperCleanup
{
ASButtonNode *firstButton = _videoNode.playButton;
XCTAssertTrue([firstButton.allTargets containsObject:_videoNode]);
ASButtonNode *secondButton = [[ASButtonNode alloc] init];
_videoNode.playButton = secondButton;
XCTAssertTrue([secondButton.allTargets containsObject:_videoNode]);
XCTAssertEqual(_videoNode, secondButton.supernode);
XCTAssertFalse([firstButton.allTargets containsObject:_videoNode]);
XCTAssertNotEqual(_videoNode, firstButton.supernode);
}
- (void)testChangingAssetsChangesPlaceholderImage - (void)testChangingAssetsChangesPlaceholderImage
{ {
UIImage *firstImage = [[UIImage alloc] init]; UIImage *firstImage = [[UIImage alloc] init];