From a4555869de5eebddd0fe5ed30c3231fdc4e1e96b Mon Sep 17 00:00:00 2001 From: Max Gu Date: Tue, 14 Jun 2016 10:15:57 -0700 Subject: [PATCH] Re-enabling HLS video constructed from URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple claims in the AVFoundationProgramming Guide that HLS videos can be constructed only through URL, but later with iOS 4.3 release notes it claimed to bring updates to how the HLS videos should be initialized, which works with asset too. I’ve tested with both, and it looks like initializing with asset is buggy. --- AsyncDisplayKit/ASVideoNode.mm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/AsyncDisplayKit/ASVideoNode.mm b/AsyncDisplayKit/ASVideoNode.mm index c00e518522..4e799398cd 100644 --- a/AsyncDisplayKit/ASVideoNode.mm +++ b/AsyncDisplayKit/ASVideoNode.mm @@ -126,14 +126,25 @@ static NSString * const kStatus = @"status"; { ASDN::MutexLocker l(__instanceLock__); + AVPlayerItem *playerItem = nil; if (_asset != nil) { - AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:_asset]; - playerItem.videoComposition = _videoComposition; - playerItem.audioMix = _audioMix; - return playerItem; + if ([_asset isKindOfClass:[AVURLAsset class]] && [self hasURLAsset]) { + playerItem = [[AVPlayerItem alloc] initWithURL:((AVURLAsset *)_asset).URL]; + _asset = [playerItem asset]; + } else { + playerItem = [[AVPlayerItem alloc] initWithAsset:_asset]; + } } - return nil; + playerItem.videoComposition = _videoComposition; + playerItem.audioMix = _audioMix; + return playerItem; +} + +- (BOOL)hasURLAsset +{ + // The array of AVAssetTrack objects available via the tracks property of an URL asset is typically empty for streaming-based media + return _asset.tracks.count == 0; } - (void)prepareToPlayAsset:(AVAsset *)asset withKeys:(NSArray *)requestedKeys