• 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
Playing sound effect in thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Playing sound effect in thread


  • Subject: Playing sound effect in thread
  • From: Rick Anderson <email@hidden>
  • Date: Fri, 30 Jan 2004 03:10:43 -0800

I'm working on an application that simulates the flipping of a page visually and I wanted to add sound of a page flip when the user does this. Initially, when I first added the sound effect, the sound didn't work as smoothly as I had intended and the sound was holding up the page flip visual. So I placed the sound code in a thread to see if that would help. It did somewhat, but it still seems jerky and it occasionally pauses for a half-second or so before anything happens. Below is the code for this. Is this the right way to do a sound in a thread or am I botching this somehow?

---------------------------------

- (void)doPageFlipSound
{
// first check to see if the preferences says to do this or not
// and return if the pref checkbox is checked
if ([prefPanelSoundFX intValue])
return;

// otherwise create a thread and start the sound playing
[NSThread detachNewThreadSelector: @selector(playPageFlipSound:) toTarget: self withObject: nil];
}

- (void)playPageFlipSound:(id)anObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[thePageFlipSound play];

[pool release];
}

----------------------------------

The sound gets defined in my awakeFromNib() function:

----------------------------------

thePageFlipSound = [[NSSound alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForSoundResource:@"pageturn-short.wav"] byReference:NO];

----------------------------------

Anyone know why this wouldn't work smoothly? Maybe some tips on any possible way to optimize this. It seems pretty simple so I'm not sure what I could do more efficiently to make it work better.


--Rick Anderson
"The only difference between me and a madman,
is that I am not mad." -- Salvador Dali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Playing sound effect in thread
      • From: Brian Christensen <email@hidden>
    • Re: Playing sound effect in thread
      • From: Jörn Salewski <email@hidden>
  • Prev by Date: drawing text
  • Next by Date: Re: building a lazy NSMenu
  • Previous by thread: drawing text
  • Next by thread: Re: Playing sound effect in thread
  • Index(es):
    • Date
    • Thread