how to play an audio soundclip when a nib is loaded - welcome screen - xcode
Posted
by Pavan
on Stack Overflow
See other posts from Stack Overflow
or by Pavan
Published on 2010-05-30T19:21:41Z
Indexed on
2010/05/30
19:42 UTC
Read the original article
Hit count: 287
I would like to do the following two things: 1) I would like to play an audio file qhen a nib is loaded 2) After that i would like to switch views when the audio file has finished playing. This will be easy as i just need to call the event that initiates the change of view by using the delegate method
-(void) audioPlayerDidFinishPlaying{
//code to change view
}
I dont know how to to play the audio file when a nib is loaded. Using the AVFoundation framework, I tried doing the following after setting up the audio player and the variables associated with it in the appropriate places i wrote the following:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"sound" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error:nil];
[fileURL release];
self.player = newPlayer;
[newPlayer release];
[player prepareToPlay];
[player setDelegate: self];
[player play];
}
Although this does not play the file as the viewdidload method gets called before the nib is shown so the audio is never played or heard.
What do i need to do so that i can play the audio file AFTER the nib has loaded and is shown on the screen? can someone please help me as ive been working on this for 3 hours now. Thanks in advance.
© Stack Overflow or respective owner