• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: problems loading a sound with NSSound
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems loading a sound with NSSound


  • Subject: Re: problems loading a sound with NSSound
  • From: Keith Blount <email@hidden>
  • Date: Mon, 8 Mar 2010 03:20:17 -0800 (PST)

NSSound doesn't respond to -initWithContentsOfFile: (it responds to -initWithContentsOfFile:byReference:), so you should be seeing errors on the console if that is how you are trying to init your NSSound object. (Also note that in the code you posted there is a memory leak, so it would be better to return [sound autorelease]).

I'm not sure why you need the -getSound: method at all, though - what is wrong with NSSound's -soundNamed:?

NSSound *logoSound = [NSSound soundNamed:@"logoSound"];
[logoSound play];

All the best,
Keith


----- Original Message ----

Hello,

I added a sound file to the resources of my project ( logoSound.AIF )

I use this function to load the resource:

-(NSSound*) getSound:(NSString *) sndValue {
    NSBundle *bundle = [ NSBundle bundleForClass: [ self class ] ];
    NSString *sndName = [ bundle pathForResource: sndValue ofType: @"aif" ];
    NSSound *sound = [ [ NSSound alloc ]
                      initWithContentsOfFile: sndName ];
    return sound;
} // getSound


I do this to load the sound file:

NSSound *logoSound = [self getSound: @"logoSound"];

I try:
[logoSound play];

but the sound doesn't play


what happend?


thanks



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: problems loading a sound with NSSound
      • From: Jonathan Chacón <email@hidden>
  • Prev by Date: NSApp question
  • Next by Date: Re: IsReadableFileAtPath
  • Previous by thread: Re: problems loading a sound with NSSound
  • Next by thread: Re: problems loading a sound with NSSound
  • Index(es):
    • Date
    • Thread