AVPlayerItem は、1 つの 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'