tags:

views:

185

answers:

2

Ok this works

- (id)initWithCoder:(NSCoder*)coder
{
 if ((self = [super initWithCoder:coder]))
  {
   // Load the sounds
  NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Begin Drawing" ofType:@"wav"]];
  AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[0]);
  soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Middle Drawing" ofType:@"wav"]];
  AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[1]);
  soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"End Drawing" ofType:@"wav"]];
  AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &_boomSoundIDs[2]);  
  }
 return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
 UITouch *touch = [touches anyObject];

 if ([touches count] == 1)
  {
  AudioServicesPlaySystemSound(_boomSoundIDs[0]);
 }

But this is what I am trying to fix

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
if ([touches count] == 1)
  {
  AudioServicesPlaySystemSound(_boomSoundIDs[1]);
 }

It just plays so continuously that the sound will not play all the way through, but begin every time the user moves their finger, I want is to actually play all the way through then loop again

+1  A: 

Before you play the sound, check to see if it's already playing.

Also please reformat your code, it's hard to read.

EightyEight
OK I fixed the formatting, sorry about that. But I don't know how to check if the sound is playing.
Jaba
If you look at the (reference for AudioServicesPlaySystemSound)[http://developer.apple.com/iphone/library/documentation/AudioToolbox/Reference/SystemSoundServicesReference/Reference/reference.html#//apple_ref/c/func/AudioServicesPlaySystemSound] you'll see that you can register a callback (through AudioServicesAddSystemSoundCompletion). Does that help?
EightyEight
Well I have already looked at that, but I just don't understand the process of adding and removing a callback especialy this one. If you could please give me an explination on this process and/or what they are doing in this then that would be great. I'm begging you.
Jaba
A callback is a function that gets called when the sound stops playing. What you want to do is set a flag when you play your sound ("sound is playing"). Next time you detect a touch event, before playing the sound first check to see if your "sound is playing" variable is set. If it's playing, you don't need to play the sound again. Finally, when the callback executes, you can unset the flag. Here's an example: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4504-how-detect-system-sound-completion.htmlYou might also want to look at other sound frameworks (OpenAL?).
EightyEight
A: 

The system sound API is probably not the best pick for what you are trying to do. Take a look at AVAudioPlayer. The API is simple and it lets you check if the sound is already playing.

zoul