wip fixing pr comments

This commit is contained in:
Luke Parham
2015-12-22 02:15:25 -06:00
parent c69e18bc6e
commit 4602e4e9eb
7 changed files with 117 additions and 43 deletions

View File

@@ -2,10 +2,11 @@
#import "ASVideoNode.h"
@interface ASVideoNode () {
@interface ASVideoNode ()
{
ASDN::RecursiveMutex _lock;
__weak id<ASVideoNodeDatasource> _datasource;
__weak id<ASVideoNodeDataSource> _dataSource;
BOOL _shouldBePlaying;
AVAsset *_asset;
@@ -23,7 +24,8 @@
@implementation ASVideoNode
- (instancetype)init {
- (instancetype)init
{
if (!(self = [super init])) { return nil; }
_playerNode = [[ASDisplayNode alloc] initWithLayerBlock:^CALayer *{
@@ -35,11 +37,14 @@
self.gravity = ASVideoGravityResizeAspect;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restartVideo:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
[self addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didPlayToEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
return self;
}
// FIXME: Adopt interfaceStateDidChange API
- (void)setInterfaceState:(ASInterfaceState)newState
{
[super setInterfaceState:newState];
@@ -51,9 +56,6 @@
if (_shouldBePlaying) {
[self play];
}
if (_spinner) {
[self addSubnode:_spinner];
}
}
}
@@ -71,9 +73,9 @@
}
}
- (void)restartVideo:(NSNotification *)notification
- (void)didPlayToEnd:(NSNotification *)notification
{
if ( [[[notification object] asset] isEqual:_asset]) {
if (ASObjectIsEqual([[notification object] asset], _asset)) {
[[((AVPlayerLayer *)_playerNode.layer) player] seekToTime:CMTimeMakeWithSeconds(0, 1)];
if (_autorepeat) {
@@ -84,18 +86,12 @@
}
}
- (void)layoutDidFinish
- (void)layout
{
[super layout];
_playerNode.frame = self.bounds;
}
- (void)didLoad {
[super didLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[self.view addGestureRecognizer:tap];
}
- (void)tapped
{
if (_shouldBePlaying) {
@@ -134,7 +130,7 @@
}
}
if (_shouldAutoPlay) {
if (_shouldAutoplay) {
[self play];
}
}
@@ -189,7 +185,8 @@
return _asset;
}
- (void)setGravity:(ASVideoGravity)gravity {
- (void)setGravity:(ASVideoGravity)gravity
{
ASDN::MutexLocker l(_lock);
switch (gravity) {
@@ -208,28 +205,25 @@
}
}
- (ASVideoGravity)gravity;
- (ASVideoGravity)gravity
{
ASDN::MutexLocker l(_lock);
if ([((AVPlayerLayer *)_playerNode.layer).contentsGravity isEqualToString:AVLayerVideoGravityResize]) {
if (ASObjectIsEqual(((AVPlayerLayer *)_playerNode.layer).contentsGravity, AVLayerVideoGravityResize)) {
return ASVideoGravityResize;
}
if ([((AVPlayerLayer *)_playerNode.layer).contentsGravity isEqualToString:AVLayerVideoGravityResizeAspectFill]) {
if (ASObjectIsEqual(((AVPlayerLayer *)_playerNode.layer).contentsGravity, AVLayerVideoGravityResizeAspectFill)) {
return ASVideoGravityResizeAspectFill;
}
return ASVideoGravityResizeAspect;
}
- (void)play;
- (void)play
{
ASDN::MutexLocker l(_lock);
[[((AVPlayerLayer *)_playerNode.layer) player] play];
_shouldBePlaying = YES;
_playButton.alpha = 0.0;
if ([self ready] && ![self.subnodes containsObject:_spinner]) {
if (!_spinner) {
_spinner = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
UIActivityIndicatorView *spinnnerView = [[UIActivityIndicatorView alloc] initWithFrame:_playButton.frame];
spinnnerView.color = [UIColor whiteColor];
@@ -237,21 +231,30 @@
return spinnnerView;
}];
}
if (![self ready]) {
[self addSubnode:_spinner];
}
[[((AVPlayerLayer *)_playerNode.layer) player] play];
_shouldBePlaying = YES;
_playButton.alpha = 0.0;
// if ([self ready] && ![self.subnodes containsObject:_spinner]) {
// }
}
- (BOOL)ready;
- (BOOL)ready
{
return [((AVPlayerLayer *)_playerNode.layer) player].currentItem.status != AVPlayerItemStatusReadyToPlay;
return [((AVPlayerLayer *)_playerNode.layer) player].currentItem.status == AVPlayerItemStatusReadyToPlay;
}
- (void)pause;
- (void)pause
{
ASDN::MutexLocker l(_lock);
[[((AVPlayerLayer *)_playerNode.layer) player] pause];
[((UIActivityIndicatorView *)_spinner.view) stopAnimating];
_shouldBePlaying = NO;
_playButton.alpha = 1.0;
}
@@ -261,6 +264,16 @@
return _currentItem;
}
- (ASDisplayNode *)spinner
{
return _spinner;
}
- (AVPlayerItem *)curentItem
{
return _currentItem;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];