一个 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'