I'm working on a new app. One of this app's view controllers has labels that can be dragged and dropped into any of the controller's collection view's cells. When it is, if the label is supposed to be in the cell it's in, then a sound is to be played. I'm not deliberately inserting the sound's corresponding player item twice, but I got the error message described in the title.
Below, I have posted some code to help you figure out why I got the error:
Below, I have posted some code to help you figure out why I got the error:
Code:
-(void)label:(UILabel *)label wasDraggedToPoint:(CGPoint)point
{
TextCell *theCell;
CGRect collectionViewFrame = [[self collectionView] frame];
if (CGRectContainsPoint(collectionViewFrame, point)) {
// The user dragged a label, and dropped it inside the collection view that displays underscores.
NSInteger index = 0;
// Convert the coordinates of point to coordinates that are relative to the collection view.
point = [[self view] convertPoint:point toView:[self collectionView]];
for (TextCell *cell in [[self collectionView] visibleCells])
{
CGRect frame = [cell frame];
if (CGRectContainsPoint(frame, point)) {
// The user dropped the label inside the cell that is represented by the variable "cell."
theCell = cell;
index = [[[self collectionView] indexPathForCell:theCell] row];
}
}
if (theCell != nil) {
NSInteger indexOfLabelText = [blahComponents indexOfObject:[label text]];
if (indexOfLabelText == index) {
// The user dragged the label to the correct cell.
[[theCell textLabel] setText:[label text]];
[label setHidden:true];
NSURL *rswmURL = [[NSBundle mainBundle] URLForResource:@"rswm" withExtension:@"m4a" subdirectory:@"sounds"];
AVPlayerItem *rswmItem = [[AVPlayerItem alloc] initWithURL:rswmURL];
[[self queuePlayer] insertItem:rswmItem afterItem:nil];
NSURL *blahSoundFileURL = [[NSBundle mainBundle] URLForResource:blah withExtension:@"m4a" subdirectory:@"sounds"];
AVPlayerItem *blahSoundPlayerItem = [[AVPlayerItem alloc] initWithURL:blahSoundFileURL];
[[self queuePlayer] insertItem:rswmItem afterItem:nil]; // This line triggers an exception breakpoint.
[[self queuePlayer] insertItem:blahSoundPlayerItem afterItem:nil];
[[self queuePlayer] play];
}
else
{
// The user did not drag the label to the correct cell.
[label setCenter:[(DraggableLabel *)label originalLocation]];
}
}
}
}