Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
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:
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]];
            }
        }
    }
    
}
 

JohnsonK

macrumors regular
Mar 6, 2014
142
0
Did you actually read the code or just copy-pasted? ;)

Code:
AVPlayerItem *rswmItem = [[AVPlayerItem alloc] initWithURL:rswmURL];
[B][[self queuePlayer] insertItem:rswmItem afterItem:nil];[/B]
NSURL *blahSoundFileURL = [[NSBundle mainBundle] URLForResource:blah withExtension:@"m4a" subdirectory:@"sounds"];
AVPlayerItem *blahSoundPlayerItem = [[AVPlayerItem alloc] initWithURL:blahSoundFileURL];
[B][[self queuePlayer] insertItem:rswmItem afterItem:nil];  // This line triggers an exception breakpoint.[/B]
[B][[self queuePlayer] insertItem:blahSoundPlayerItem afterItem:nil];[/B]
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Did you actually read the code or just copy-pasted? ;)

Code:
AVPlayerItem *rswmItem = [[AVPlayerItem alloc] initWithURL:rswmURL];
[B][[self queuePlayer] insertItem:rswmItem afterItem:nil];[/B]
NSURL *blahSoundFileURL = [[NSBundle mainBundle] URLForResource:blah withExtension:@"m4a" subdirectory:@"sounds"];
AVPlayerItem *blahSoundPlayerItem = [[AVPlayerItem alloc] initWithURL:blahSoundFileURL];
[B][[self queuePlayer] insertItem:rswmItem afterItem:nil];  // This line triggers an exception breakpoint.[/B]
[B][[self queuePlayer] insertItem:blahSoundPlayerItem afterItem:nil];[/B]

I noticed that last night. :rolleyes: Thanks, anyways!
 

JohnsonK

macrumors regular
Mar 6, 2014
142
0
I noticed that last night. :rolleyes: Thanks, anyways!

Cool, don't forget to mark as resolved and try not make copy-paste code a habit, it is bad and you won't ever learn anything from it. I bet you still don't know exactly what your code does and why it is wrong ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.