diff --git a/AsyncDisplayKit/ASVideoNode.h b/AsyncDisplayKit/ASVideoNode.h index 103124b38d..86870a83c2 100644 --- a/AsyncDisplayKit/ASVideoNode.h +++ b/AsyncDisplayKit/ASVideoNode.h @@ -41,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isPlaying; @property (nullable, nonatomic, strong, readwrite) AVAsset *asset; +@property (nullable, atomic, strong, readwrite) NSURL *assetURL; @property (nullable, nonatomic, strong, readwrite) AVVideoComposition *videoComposition; @property (nullable, nonatomic, strong, readwrite) AVAudioMix *audioMix; @@ -142,4 +143,4 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END -#endif \ No newline at end of file +#endif diff --git a/AsyncDisplayKit/ASVideoNode.mm b/AsyncDisplayKit/ASVideoNode.mm index 686950fbae..6160c31a00 100644 --- a/AsyncDisplayKit/ASVideoNode.mm +++ b/AsyncDisplayKit/ASVideoNode.mm @@ -69,6 +69,7 @@ static NSString * const kStatus = @"status"; ASVideoNodePlayerState _playerState; AVAsset *_asset; + NSURL *_assetURL; AVVideoComposition *_videoComposition; AVAudioMix *_audioMix; @@ -127,13 +128,10 @@ static NSString * const kStatus = @"status"; ASDN::MutexLocker l(__instanceLock__); AVPlayerItem *playerItem = nil; - if (_asset != nil) { - if ([_asset isKindOfClass:[AVURLAsset class]] && [self hasURLAsset]) { - playerItem = [[AVPlayerItem alloc] initWithURL:((AVURLAsset *)_asset).URL]; - _asset = [playerItem asset]; - } else { - playerItem = [[AVPlayerItem alloc] initWithAsset:_asset]; - } + if (_assetURL != nil) { + playerItem = [[AVPlayerItem alloc] initWithURL:_assetURL]; + } else if (_asset != nil) { + playerItem = [[AVPlayerItem alloc] initWithAsset:_asset]; } playerItem.videoComposition = _videoComposition; @@ -448,6 +446,34 @@ static NSString * const kStatus = @"status"; _playerState = playerState; } +- (void)setAssetURL:(NSURL *)assetURL +{ + ASDN::MutexLocker l(__instanceLock__); + + if ([_asset isKindOfClass:[AVURLAsset class]]) { + if (ASObjectIsEqual(assetURL, ((AVURLAsset *)_asset).URL)) { + return; + } + } + + [self clearFetchedData]; + + _asset = [AVURLAsset assetWithURL:assetURL]; + + [self setNeedsDataFetch]; +} + +- (NSURL *)assetURL +{ + ASDN::MutexLocker l(__instanceLock__); + + if ([_asset isKindOfClass:AVURLAsset.class]) { + return ((AVURLAsset *)_asset).URL; + } + + return nil; +} + - (void)setAsset:(AVAsset *)asset { ASDN::MutexLocker l(__instanceLock__);