Quote:
Originally Posted by starwarsdevwookie59
thanks for your help. for anyone reading this, the code i ended up using to play "sound1.wav" was:
NSString *tmpFileName = [[NSString alloc] initWithFormat:@"sound1"];
NSString *fileName = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName], &soundID);
AudioServicesPlaySystemSound (soundID);
[tmpFileName release];
|
I am using this pattern to play audio. It works fine when initiated from a UI action such as pressing a button. I am implementing an animation sequence with sound in a thread which is dispatched as follows:
Code:
[NSThread detachNewThreadSelector:@selector(displayAnimation:) toTarget:self withObject:nil];
Now, this all works fine. In my selector I have to call the following to get render to my view:
Code:
for ( int i = 0; i < c; i++ ) {
KeyFrame *frame = [frameArray objectAtIndex:i];
int waitTime = [frame duration];
UIImage *image = [frame image];
[self performSelectorOnMainThread:@selector(drawFrame:) withObject:image waitUntilDone:YES];
usleep(waitTime * 1000.0);
}
I added the same pattern to play the sound thinking that it needs to be initiated from the main thread but nothing.
Code:
if ( soundPath != nil ) {
[self performSelectorOnMainThread:@selector(playSound:) withObject:soundPath waitUntilDone:YES];
}
...
-(void) playSound:(id)path
{
NSLog( @"Playing sound from path: %@\n", path );
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
}
I tried adding the code:
Code:
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"you_are_nice" ofType:@"mp3"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound(soundID);
To the beginning of the viewDidLoad and still nothing. When I look at the package in ../Library/Application Support/iPhone Simulator/... I see the mp3 file so I am at a loss.
Any help debugging this or suggestions what to look at would be very grateful.
Thanks!
Bryan