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

ghall

macrumors 68040
Original poster
Jun 27, 2006
3,771
1
Rhode Island
So I've been trying to get my app to play a subtle sound when one viewController slide-transitions into another but I'm having a problem. I've done troubleshooting for the past few days to narrow down the issue and I've narrowed it down to the following code:
Code:
 NSString *soundPath = [[NSBundle mainBundle] pathForResource: @"slide" ofType: @"aif"];
    NSLog(@"soundPath = %@", soundPath);

When I run my app the second line prints out as 'soundPath = (null)' and the if statement to run the rest of the code fails because the next NSLog never prints. Here's that code for reference if it helps any.

Code:
if ([[NSFileManager defaultManager] fileExistsAtPath:soundPath])
    {
        NSLog(@"slide.aif loaded");
        NSURL* slideSoundURL = [NSURL fileURLWithPath:soundPath];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)slideSoundURL, &slideSound);
    }

From what I can gather, the file isn't being found, even though it definitely exists in my project with the exact same spelling, case, and file format extension. Any ideas what could be going wrong?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
How did you add your slide.aif to your project? Did you make sure to copy it (and not just link it)? Click on the file in your Project Navigator (left side) and examine the Full Path in your File Inspector (right side). Does it seem to be part of the project bundle (proper directory)?
 

ghall

macrumors 68040
Original poster
Jun 27, 2006
3,771
1
Rhode Island
Yes, I copied the file when I added it. Its in the same directory as the rest of the project. In the Project Navigator I have it in a group though, but am I right that it shouldn't matter as long as it's in the same directory in the filesystem?
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
Could we perhaps see a screenshot of Xcode with the file highlighted and the properties inspector shown (feel free to blur out any private information you don't want us to see)

----------

Also, I am not that familiar with audio files, but according to filext.com, the macintosh extension is .aiff so maybe that has something to do with it.
 

ghall

macrumors 68040
Original poster
Jun 27, 2006
3,771
1
Rhode Island
Well I feel dumb. :p

I did a once over of the file properties in Xcode so make sure that I posted everything, and I discovered that my project wasn't selected in Target Memberships. Don't know how that happened, but I checked that and the issue was fixed. I've been trying to figure that out for a week.

Anyway, I think I have to resign my geek card now. ;)
 

waterskier2007

macrumors 68000
Jun 19, 2007
1,871
228
Novi, MI
Well I feel dumb. :p

I did a once over of the file properties in Xcode so make sure that I posted everything, and I discovered that my project wasn't selected in Target Memberships

Ah yeah, that makes sense. When you add an external file, the dialog box gives you the option to check the target membership. Make sure you do that.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Well I feel dumb. :p

I did a once over of the file properties in Xcode so make sure that I posted everything, and I discovered that my project wasn't selected in Target Memberships. Don't know how that happened, but I checked that and the issue was fixed. I've been trying to figure that out for a week.

Anyway, I think I have to resign my geek card now. ;)

Don't feel bad. Show me an experienced iOS or Mac OS developer who hasn't been bitten by this at least a half-dozen times and I'll show you somebody who isn't as experienced as they claim.

I sometimes think there is a gremlin in Xcode that changes the state of this checkbox on projects at random intervals. :)

The good news is that now that you've had a traumatic experience with the target membership checkbox, you'll check it much sooner next time. Pain teaches us lessons.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.