Tuesday, December 15, 2009

playing sound infinitie and then stop on click

in .h add
#import AudioToolbox/AudioServices.h
#import AVFoundation/AVFoundation.h


and declare
AVAudioPlayer *audioPlayer

in .m

inside 1st loaded ()

NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@"2000hz" ofType:@"wav"];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];

[audioPlayer setDelegate:self];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer prepareToPlay];
BOOL plays = [audioPlayer play];



and to stop sound
write this on view change


[audioPlayer stop];

No comments:

FEEDJIT Live