View Full Version : Play sound after screen loads.
KardelSharpeye
Jun 2, 2009, 02:31 PM
Good morning all,
I am trying to play the intro sound for an application. However the sounds always play before the first screen ever loads. Even if I execute the play sound function after I have load/initialize all my views. Is there any event I can listen to like AS3.0 ( Event.addedToStage)? or anyway I can do so that the sound plays after the intro screen is visible to user?
Thanks all.
johnnyjibbs
Jun 3, 2009, 05:00 AM
Put your code in the viewDidAppear method of your view controller where you want to play the sound. It gets called immediately after the view has appeared and become visible.
KardelSharpeye
Jun 3, 2009, 11:42 AM
Put your code in the viewDidAppear method of your view controller where you want to play the sound. It gets called immediately after the view has appeared and become visible.
yeh so here is my code
- (void)viewDidLoad {
myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) viewController:self];
[self.view addSubview:myView];
[introSound play];
}
and i also tried viewDidAppear but if i tell it to play the sound in here i get nothing...
dejo
Jun 3, 2009, 11:44 AM
viewDidLoad != viewDidAppear
KardelSharpeye
Jun 3, 2009, 11:59 AM
viewDidLoad != viewDidAppear
haha yeah sorry i saw that...but yeh i managed to get the sound play in viewDidAppear but it is still a second early before myView is visible.
- (void)viewDidAppear:(BOOL)animated {
[introSound play];
}
dejo
Jun 3, 2009, 12:08 PM
Instead of playing the sound in the viewDidAppear method of the superview, why not try playing it in the viewDidAppear method of the MyView?
KardelSharpeye
Jun 3, 2009, 12:12 PM
Instead of playing the sound in the viewDidAppear method of the superview, why not try playing it in the viewDidAppear method of the MyView?
hmm yeh i tried that i think its only called in the view controller.
dejo
Jun 3, 2009, 12:13 PM
hmm yeh i tried that i think its only called in the view controller.
And that's still too early? Maybe add a delay via an NSTimer?
KardelSharpeye
Jun 3, 2009, 12:25 PM
And that's still too early? Maybe add a delay via an NSTimer?
yeh i guess this is the only way. thanks guys.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.