Issues loading an audio file

Discussion in 'iOS Programming' started by ghall, Mar 4, 2014.

  1. ghall macrumors 68040

    ghall

    Joined:
    Jun 27, 2006
    Location:
    Rhode Island
    #1
    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?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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)?
     
  3. ghall thread starter macrumors 68040

    ghall

    Joined:
    Jun 27, 2006
    Location:
    Rhode Island
    #3
    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?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Yes, that's correct.
     
  5. ghall thread starter macrumors 68040

    ghall

    Joined:
    Jun 27, 2006
    Location:
    Rhode Island
    #5
    Hmmm. I'm pretty stumped then. I can't find anything else that might be a problem. :(
     
  6. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #6
    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.
     
  7. ghall thread starter macrumors 68040

    ghall

    Joined:
    Jun 27, 2006
    Location:
    Rhode Island
    #7
    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. ;)
     
  8. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #8
    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.
     
  9. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #9
    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.
     

Share This Page