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:
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'
There is a semi-legal way that might break in the future. The player item has a private method (and, it seems, variable) named _player
. You can query it like this (which technically doesn't use private API, so I think it should be AppStore-safe):
id player = [item valueForKey:@"player"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With