• 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
NSSound play often fails
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSSound play often fails


  • Subject: NSSound play often fails
  • From: James Walker <email@hidden>
  • Date: Mon, 03 Aug 2009 11:28:04 -0700

I'm having trouble getting sounds to play reliably. When it happens, -[NSSound play] returns YES, but I hear nothing, and the sound:didFinishPlaying: delegate method is not called. The sound in question is an AIFF file with a duration of about half a second. It seems like whether it fails depends on how much other computation is going on after the play call, like maybe if it can't get enough CPU time right away, it gives up.


Here's my sound playing code.


@interface PlayDelegate : NSObject - (id) init; - (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedPlaying; @end

@implementation PlayDelegate

- (id) init
{
	if ( (self == [super init]) != nil )
	{
	}
	return self;
}

- (void)sound:(NSSound *)sound
	didFinishPlaying:(BOOL)finishedPlaying
{
	[sound setDelegate: nil];
	[sound release];

	#if LOG_PLAY
		NSLog( @"Finished sound play %s",
			finishedPlaying? "successfully" : "unsuccessfully" );
	#endif
}

@end

static PlayDelegate*	sPlayDelegate = nil;


void PlayNamedSound( CFStringRef inSoundName ) { NSSound* theSound = [NSSound soundNamed: (NSString*) inSoundName ]; if (theSound != nil) { [theSound retain]; if (sPlayDelegate == nil) { sPlayDelegate = [[PlayDelegate alloc] init]; } [theSound setDelegate: sPlayDelegate]; BOOL startedPlay = [theSound play]; #if LOG_PLAY NSLog( @"Started sound play %s", startedPlay? "successfully" : "unsuccessfully" ); #endif } else { NSLog(@"Missing sound resource %@.", (NSString*) inSoundName ); } }

--
  James W. Walker, Innoventive Software LLC
  <http://www.frameforge3d.com/>
_______________________________________________

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: NSSound play often fails
      • From: Jerry Krinock <email@hidden>
  • Prev by Date: Re: Table view data source methods order?
  • Next by Date: addSubview: and positioning at the bottom of a NSWindow
  • Previous by thread: Non-blocking custom event loop?
  • Next by thread: Re: NSSound play often fails
  • Index(es):
    • Date
    • Thread