delay on touches
i get two strange effects using button to play and stop sounds:
1st: when i start the app the sound has a short delay on the FIRST touch, not on the following.
2nd: i want to stop the sound when lifting the finger. it works touching and releasing not to fast. when tapping fast, no sound is playing.
it seems that the "stop" IBAction is reacting faster that the "play" action.
i tried not using buttons but Touches Events - same result.
where could be the failure?
//Touch Down
- (void)play {
AVAudioPlayer *player =
[[AVAudioPlayer alloc] initWithContentsOfURL:(NSURL *)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"%"ofType:@"caf"]] error:nil];
if (nil != player) {
[player setDelegate:self];
[player play];
} else {
NSLog(@"Failed to allocate AVAudioPlayer object!");
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
if (flag == NO) NSLog(@"Playback finished unsuccessfully!");
[player setDelegate:nil];
[player release];
}
- (IBAction)D2:(id)sender {
D2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"D2" ofType:@"caf"]] error:nil];
D2.delegate = self;
[D2 play];
}
//Touch Up Inside
- (IBAction)D2stop:(id)sender {
D2.delegate = self;
[D2 release];
[D2 stop];
}
|