Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 0859542

Browse files
maickigarrettmoon
authored andcommitted
Cleanup ASVideoNode a bit
1 parent 03fb703 commit 0859542

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

AsyncDisplayKit/ASVideoNode.mm

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ @implementation ASVideoNode
9090

9191
// TODO: Support preview images with HTTP Live Streaming videos.
9292

93-
#pragma mark - Construction and Layout
93+
#pragma mark - Lifecycle
94+
9495

9596
- (instancetype)init
9697
{
@@ -228,6 +229,22 @@ - (void) removePlayerObservers:(AVPlayer *)player
228229
}
229230
}
230231

232+
- (void)_fetchDataForVideoNode
233+
{
234+
[self setNeedsPreload];
235+
}
236+
237+
- (void)_clearVideoNode
238+
{
239+
self.videoPlaceholderImage = nil;
240+
self.player = nil;
241+
self.currentItem = nil;
242+
self.playerState = ASVideoNodePlayerStateUnknown;
243+
}
244+
245+
#pragma mark - Layout
246+
247+
231248
- (void)layout
232249
{
233250
[super layout];
@@ -301,7 +318,7 @@ - (void)setVideoPlaceholderImage:(UIImage *)image
301318
if (image != nil) {
302319
self.contentMode = ASContentModeFromVideoGravity(_gravity);
303320
}
304-
[self __setImage:image];
321+
self.image = image;
305322
}
306323

307324
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
@@ -413,10 +430,7 @@ - (void)didExitPreloadState
413430

414431
{
415432
ASDN::MutexLocker l(__instanceLock__);
416-
417-
self.player = nil;
418-
self.currentItem = nil;
419-
self.playerState = ASVideoNodePlayerStateUnknown;
433+
[self _clearVideoNode];
420434
}
421435
}
422436

@@ -507,10 +521,15 @@ - (AVAsset *)asset
507521

508522
- (void)_setAndFetchAsset:(AVAsset *)asset url:(NSURL *)assetURL
509523
{
510-
[self didExitPreloadState];
511-
_asset = asset;
512-
_assetURL = assetURL;
513-
[self setNeedsPreload];
524+
[self _clearVideoNode];
525+
526+
{
527+
ASDN::MutexLocker l(__instanceLock__);
528+
_asset = asset;
529+
_assetURL = assetURL;
530+
}
531+
532+
[self _fetchDataForVideoNode];
514533
}
515534

516535
- (void)setVideoComposition:(AVVideoComposition *)videoComposition
@@ -619,7 +638,7 @@ - (void)play
619638
}
620639

621640
if (_player == nil) {
622-
[self setNeedsPreload];
641+
[self _fetchDataForVideoNode];
623642
}
624643

625644
if (_playerNode == nil) {

0 commit comments

Comments
 (0)