一个AVPlayerItem只能分配给一个AVPlayer。一旦将AVPlayerItem添加到AVPlayer中,将来尝试将其添加到另一个AVPlayer将导致应用程序崩溃(SIGABRT)。
因此,给定AVPlayerItem,您如何确定:
- 它当前关联的AVPlayer是哪个?以及
- 在过去的任何时间点是否曾将其插入到AVPlayer中?
以下代码可靠地演示了该问题:
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];
以下是错误信息:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An AVPlayerItem cannot be associated with more than one instance of AVPlayer'