views:

16

answers:

2

I have an audio file that I want to begin playing at a 20 second delay, after the user has seen some animations play etc...

does anyone know how I might go about doing this? I have 5 animations that play, after which I would like to audio file to begin. the whole thing would keep cycling until the user exits the app.

here's the code I have that plays the audio file. I can get it to play if a button is pressed or on viewDidLoad, that works fine.

NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"]; CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath]; AudioServicesCreateSystemSoundID(audioURL, &audioID);

AudioServicesPlaySystemSound(audioID);

thanks for any help

+1  A: 

If you know its always going to be exactly 20 seconds then you can use an NSTimer to call a method that starts the audio:

[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(startPlaying) userInfo:nil repeats:NO];


-(void)startPlaying {

    NSString *audioSoundPath = [[ NSBundle mainBundle] pathForResource:@"audio_file" ofType:@"caf"];
    CFURLRef audioURL = (CFURLRef) [NSURL fileURLWithPath:audioSoundPath];
    AudioServicesCreateSystemSoundID(audioURL, &audioID);
    AudioServicesPlaySystemSound(audioID);
}
Ben
that should do the trick. thanks a lot.
hanumanDev
+1  A: 

You can also use

[self performSelector: @selector(playSound:) withObject: audioURL afterDelay: 20.0f];

jv42
Of course you can choose to pass anything you want as parameter, as long as it can be cast to `id`.
jv42
that great. thanks so much.
hanumanDev