I hope the name is not too misleading ... :)
I play system sound and add SoundCompletion-Callback like this:
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);
While "I" is a simple NSObject
In the completion callback, I will try again to repeat the playback procedure:
I had to add __bridge_transfer and __bridge_retained in the role, otherwise I get errors, crashes or other unexpected behavior.
But all this does not work, despite all this.
I store sounds for playback in NSMutableArray, grab the first record of the array and play it back, add sound and hope the material happens. But - with all the things left in the transfer, NSMutableArray is empty in the second call ...
Here is the code:
static void completionCallback (SystemSoundID mySSID, void *myself) {
NSLog(@"Audio callback");
AudioServicesRemoveSystemSoundCompletion (mySSID);
AudioServicesDisposeSystemSoundID(mySSID);
[(__bridge_transfer Speaker *)myself speakCharacter];
CFRelease(myself);
}
-(void)speakCharacter{
if([sounds count] > 0){
NSString *soundToPlay = [sounds objectAtIndex:0];
[sounds removeObjectAtIndex:0];
NSLog(@"TxtToSpeak %@", soundToPlay);
CFURLRef soundFileURLRef;
NSURL *path = [[NSBundle mainBundle] URLForResource:[soundToPlay uppercaseString] withExtension:@"aif"];
soundFileURLRef = (__bridge CFURLRef)path;
SystemSoundID soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);
AudioServicesPlaySystemSound (soundID);
}
}
[EDIT] - ANSWER YOUR OWN QUESTION:
:)
, .
:
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);
:
myClass *theClass = (__bridge myClass *)myself;
CFRelease(myself);
[theClass playNextSound];
...