From af37a48421567531b77f7dc86370ab04e483c64d Mon Sep 17 00:00:00 2001 From: Luke Parham Date: Thu, 28 Jan 2016 23:34:16 -0800 Subject: [PATCH 1/3] removed unnecessary clear color and improved comment --- AsyncDisplayKit/Private/ASDefaultPlayButton.m | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/AsyncDisplayKit/Private/ASDefaultPlayButton.m b/AsyncDisplayKit/Private/ASDefaultPlayButton.m index 371c598f..7cf9f6d4 100644 --- a/AsyncDisplayKit/Private/ASDefaultPlayButton.m +++ b/AsyncDisplayKit/Private/ASDefaultPlayButton.m @@ -27,24 +27,18 @@ CGRect buttonBounds = CGRectMake(originX, bounds.size.height/4, bounds.size.width/2, bounds.size.height/2); CGFloat widthHeight = buttonBounds.size.width; + //When the video isn't a square, the lower bound should be used to figure out the circle size if (bounds.size.width < bounds.size.height) { - //then use the width to determine the rect size then calculate the origin x y widthHeight = bounds.size.width/2; originX = (bounds.size.width - widthHeight)/2; buttonBounds = CGRectMake(originX, (bounds.size.height - widthHeight)/2, widthHeight, widthHeight); } if (bounds.size.width > bounds.size.height) { - //use the height widthHeight = bounds.size.height/2; originX = (bounds.size.width - widthHeight)/2; buttonBounds = CGRectMake(originX, (bounds.size.height - widthHeight)/2, widthHeight, widthHeight); } - - if (!isRasterizing) { - [[UIColor clearColor] set]; - UIRectFill(bounds); - } - + CGContextRef context = UIGraphicsGetCurrentContext(); // Circle Drawing From 2d1499ab4f623e796b4fc09af904d35e15e40105 Mon Sep 17 00:00:00 2001 From: Luke Parham Date: Fri, 29 Jan 2016 09:27:48 -0800 Subject: [PATCH 2/3] added muting property and delegate callback to override video tapping --- AsyncDisplayKit.xcodeproj/project.pbxproj | 16 +++++++++ AsyncDisplayKit/ASVideoNode.h | 3 ++ AsyncDisplayKit/ASVideoNode.mm | 36 ++++++++++++++++--- AsyncDisplayKit/Private/ASDefaultPlayButton.m | 1 - examples/Videos/Sample/ViewController.m | 14 ++++++-- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index fe19c592..b67b61ef 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -1616,6 +1616,7 @@ 058D09B9195D04C000B7D73C /* Frameworks */, 058D09BA195D04C000B7D73C /* Resources */, 3B9D88CDF51B429C8409E4B6 /* Copy Pods Resources */, + FB42E06CF915B60406431170 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -1745,6 +1746,21 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; + FB42E06CF915B60406431170 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AsyncDisplayKitTests/Pods-AsyncDisplayKitTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/AsyncDisplayKit/ASVideoNode.h b/AsyncDisplayKit/ASVideoNode.h index 7df171d0..515dc20f 100644 --- a/AsyncDisplayKit/ASVideoNode.h +++ b/AsyncDisplayKit/ASVideoNode.h @@ -24,6 +24,8 @@ @property (nonatomic, assign, readwrite) BOOL shouldAutoplay; @property (nonatomic, assign, readwrite) BOOL shouldAutorepeat; +@property (nonatomic, assign, readwrite) BOOL muted; + @property (atomic) NSString *gravity; @property (atomic) ASButtonNode *playButton; @@ -39,5 +41,6 @@ @protocol ASVideoNodeDelegate @optional - (void)videoPlaybackDidFinish:(ASVideoNode *)videoNode; +- (void)videoNodeWasTapped:(ASVideoNode *)videoNode; @end diff --git a/AsyncDisplayKit/ASVideoNode.mm b/AsyncDisplayKit/ASVideoNode.mm index f6f717f4..6ba344d3 100644 --- a/AsyncDisplayKit/ASVideoNode.mm +++ b/AsyncDisplayKit/ASVideoNode.mm @@ -19,6 +19,8 @@ BOOL _shouldAutorepeat; BOOL _shouldAutoplay; + + BOOL _muted; AVAsset *_asset; @@ -31,6 +33,7 @@ ASDisplayNode *_playerNode; ASDisplayNode *_spinner; NSString *_gravity; + dispatch_queue_t _previewQueue; } @@ -137,6 +140,7 @@ AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init]; if (!_player) { _player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]]; + _player.muted = _muted; } playerLayer.player = _player; playerLayer.videoGravity = [self gravity]; @@ -176,10 +180,14 @@ - (void)tapped { - if (_shouldBePlaying) { - [self pause]; + if (self.delegate && [self.delegate respondsToSelector:@selector(videoNodeWasTapped:)]) { + [self.delegate videoNodeWasTapped:self]; } else { - [self play]; + if (_shouldBePlaying) { + [self pause]; + } else { + [self play]; + } } } @@ -209,11 +217,11 @@ [_player replaceCurrentItemWithPlayerItem:_currentItem]; } else { _player = [[AVPlayer alloc] initWithPlayerItem:_currentItem]; + _player.muted = _muted; } } } - - (void)clearFetchedData { [super clearFetchedData]; @@ -231,11 +239,14 @@ if (_shouldAutoplay && _playerNode.isNodeLoaded) { [self play]; + } else if (_shouldAutoplay) { + _shouldBePlaying = YES; } if (isVisible) { if (_playerNode.isNodeLoaded) { if (!_player) { _player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]]; + _player.muted = _muted; } ((AVPlayerLayer *)_playerNode.layer).player = _player; } @@ -256,7 +267,7 @@ [self addSubnode:playButton]; - [_playButton addTarget:self action:@selector(play) forControlEvents:ASControlNodeEventTouchUpInside]; + [_playButton addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside]; } - (ASButtonNode *)playButton @@ -310,6 +321,20 @@ return _gravity; } +- (BOOL)muted +{ + ASDN::MutexLocker l(_lock); + + return _muted; +} + +- (void)setMuted:(BOOL)muted +{ + ASDN::MutexLocker l(_lock); + + _muted = muted; +} + #pragma mark - Video Playback - (void)play @@ -330,6 +355,7 @@ AVPlayerLayer *playerLayer = [[AVPlayerLayer alloc] init]; if (!_player) { _player = [AVPlayer playerWithPlayerItem:[[AVPlayerItem alloc] initWithAsset:_asset]]; + _player.muted = _muted; } playerLayer.player = _player; playerLayer.videoGravity = [self gravity]; diff --git a/AsyncDisplayKit/Private/ASDefaultPlayButton.m b/AsyncDisplayKit/Private/ASDefaultPlayButton.m index 7cf9f6d4..364b86a6 100644 --- a/AsyncDisplayKit/Private/ASDefaultPlayButton.m +++ b/AsyncDisplayKit/Private/ASDefaultPlayButton.m @@ -44,7 +44,6 @@ // Circle Drawing UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect: buttonBounds]; [[UIColor colorWithWhite:0.0 alpha:0.5] setFill]; - [ovalPath stroke]; [ovalPath fill]; // Triangle Drawing diff --git a/examples/Videos/Sample/ViewController.m b/examples/Videos/Sample/ViewController.m index d36c928e..5c4c0488 100644 --- a/examples/Videos/Sample/ViewController.m +++ b/examples/Videos/Sample/ViewController.m @@ -43,7 +43,6 @@ videoNode.backgroundColor = [UIColor lightGrayColor]; -// videoNode.playButton = [self playButton]; return videoNode; } @@ -61,7 +60,8 @@ nicCageVideo.backgroundColor = [UIColor lightGrayColor]; nicCageVideo.shouldAutorepeat = YES; -// nicCageVideo.playButton = [self playButton]; + nicCageVideo.shouldAutoplay = YES; + nicCageVideo.muted = YES; return nicCageVideo; } @@ -79,7 +79,6 @@ simonVideo.backgroundColor = [UIColor lightGrayColor]; simonVideo.shouldAutorepeat = YES; -// simonVideo.playButton = [self playButton]; simonVideo.shouldAutoplay = YES; return simonVideo; @@ -99,6 +98,15 @@ return playButton; } +- (void)videoNodeWasTapped:(ASVideoNode *)videoNode +{ + if (videoNode.player.muted == YES) { + videoNode.player.muted = NO; + } else { + videoNode.player.muted = YES; + } +} + - (BOOL)prefersStatusBarHidden { return YES; From 2313b3240619972e2808f2ae43ee7dc34d3bb0e4 Mon Sep 17 00:00:00 2001 From: Luke Parham Date: Fri, 29 Jan 2016 16:31:54 -0800 Subject: [PATCH 3/3] removed comment --- AsyncDisplayKitTests/ASVideoNodeTests.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/AsyncDisplayKitTests/ASVideoNodeTests.m b/AsyncDisplayKitTests/ASVideoNodeTests.m index 50b06c1a..465636f2 100644 --- a/AsyncDisplayKitTests/ASVideoNodeTests.m +++ b/AsyncDisplayKitTests/ASVideoNodeTests.m @@ -73,8 +73,6 @@ XCTAssertEqualObjects(item, secondItem); } -//Touch Handling - - (void)testSpinnerDefaultsToNil { XCTAssertNil(_videoNode.spinner);