I started a new project with a single view and added this code to the view controller:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *videoURL;
videoURL = [NSURL URLWithString:@"https://s3.amazonaws.com/xxxxxx.mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem addObserver:self
forKeyPath:@"status"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:@"AVPlayerStatus"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (context == @"AVPlayerStatus") {
NSLog(@"AVPlayerStatus changed");
if ([object isKindOfClass:[AVPlayerItem class]] && [keyPath isEqualToString:@"status"]) {
NSLog(@"Ready to play");
}
else if (((AVPlayerItem *)object).status == AVPlayerStatusFailed) {
NSLog(@"Failed to Ready");
}
else if (((AVPlayerItem *)object).status == AVPlayerStatusUnknown) {
NSLog(@"Not known");
}
}
}
The output is:
2016-06-21 19:57:56.911 VideoTest[5740:1334235] AVPlayerStatus changed
2016-06-21 19:57:56.911 VideoTest[5740:1334235] Not known
Why doesn't the AVPlayerItem ever load? and how can I get it to load?