Re-enabling HLS video constructed from URL

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.
This commit is contained in:
Max Gu
2016-06-14 10:15:57 -07:00
committed by Max Gu
parent fceae5d2f8
commit a4555869de

View File

@@ -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<NSString *> *)requestedKeys