I am using AudioServicesPlaySystemSound inside a function, can I pass the SystemSoundID variable back to calling program
I am using Xcode 4.2 I have created a function to play an array of sound clips sequentialy as follows:
//------------------------------- //F开发者_如何转开发UNCTION TO recite quad game messages //------------------------------- void SayQuad(int pageNumber, NSMutableArray quadSounds[]) { NSString *fileName= [quadSounds objectAtIndex:pageNumber]; NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"]; SystemSoundID sayIt; NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((CFURLRef)filePath, &sayIt); AudioServicesPlaySystemSound(sayIt);
} now based on a user action, I want to cancel the sound clip before it ends. This can be done with: AudioServicesDisposeSystemSoundID(sayIt); However the variable "sayIt" needs to be passed back to the calling program. I am new at this and simply do not know how to do this. I have tried setting up pointer variables but can't even get them to compile.Any help would be greatly appreciated.
First please take care to format your code correctly, so we can easily read it. It should like like this:
void SayQuad(int pageNumber, NSMutableArray quadSounds[]) {
NSString *fileName = [quadSounds objectAtIndex:pageNumber];
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];
SystemSoundID sayIt;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &sayIt);
AudioServicesPlaySystemSound(sayIt);
}
Next please read carefully what Apple provides: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_AudioVideo_iPhone/_index.html You are using The SystemSoundServices. To have control over the playback you need to use AVAudioPlayer or another one like OpenAL. This is all written in the docs Apple provides.
精彩评论