Skip to content

Commit

Permalink
[Cherry-pick] Build AVPlayerItem from the URL for HLS videos
Browse files Browse the repository at this point in the history
Summary:
Upstream PR: facebookarchive#1748

Apple claims in the [[ https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html | AVFoundationProgramming Guide ]] that HLS videos can be constructed only through URL, but later with [[ https://developer.apple.com/library/ios/releasenotes/AudioVideo/RN-AVFoundation-Old/ | 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.  The first initialization would be successful, however if you re-initialize it again within a few seconds, the asset won’t be loaded successfully ([[ https://www.dropbox.com/s/5yqn9nvce2rga1m/HLS_constructed_with_asset.mov?dl=0 | simulator recording ]]).  I am reverting this to constructing AVPlayerItem using URL for HLS videos, which solves the bug ([[ https://www.dropbox.com/s/h2b59c2q1jnkb17/HLS_constructed_from_url.mov?dl=0 | simulator recording ]]).

This issue has been discussed earlier by others but it didn't seem to work out the way we wanted: facebookarchive#1600

Reviewers: bin, yunnanwu, levi, garrett, schneider

Reviewed By: garrett, schneider

Subscribers: garrett, levi

Differential Revision: https://phabricator.pinadmin.com/D100271
  • Loading branch information
Max Gu committed Jun 30, 2016
1 parent 284160b commit 70b5198
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions AsyncDisplayKit/ASVideoNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,22 @@ - (AVPlayerItem *)constructPlayerItem
{
ASDN::MutexLocker l(_videoLock);

AVPlayerItem *playerItem = nil;
if (_asset != nil) {
return [[AVPlayerItem alloc] initWithAsset:_asset];
if ([_asset isKindOfClass:[AVURLAsset class]] && [self hasHLSAsset]) {
playerItem = [[AVPlayerItem alloc] initWithURL:((AVURLAsset *)_asset).URL];
} else {
playerItem = [[AVPlayerItem alloc] initWithAsset:_asset];
}
}

return nil;
return playerItem;
}

- (BOOL)hasHLSAsset
{
return _asset.tracks.count == 0;
}
- (void)prepareToPlayAsset:(AVAsset *)asset withKeys:(NSArray<NSString *> *)requestedKeys
{
for (NSString *key in requestedKeys) {
Expand Down

0 comments on commit 70b5198

Please sign in to comment.