15
An AVPlayerItem can only ever be assigned to one AVPlayer. Once an AVPlayerItem has been added to an AVPlayer, future attempts to add it to a different AVPlayer will SIGABRT the app.
So, given an AVPlayerItem, how can you determine:
- What AVPlayer it is currently associated with? and
- If it has ever been inserted into an AVPlayer at any point in the past?
The following code demonstrates the problem reliably:
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
AVPlayer *firstPlayer = [[AVPlayer alloc] init];
[firstPlayer replaceCurrentItemWithPlayerItem:item];
AVPlayer *secondPlayer = [[AVPlayer alloc] init];
[secondPlayer replaceCurrentItemWithPlayerItem:item];
And here's the error message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'