I would like to play a sound as soon as a page dispalyed. I am currently playing sounds using a IBAction doSound after a button is pressed. This works as intended. But, I am also wanting to play music or a short verbal instruction as soon as the page is displayed. I would like to use the same IBAction since it is already set up, but was not sure if this is a correct use of the function.
+1
A:
Override the method viewDidLoad
and put your audio playing code there. That will make it so every time a page is displayed a sound will start up.
If you only want a sound to be played once go to your appDelegate.m and override the method that says didFinishLaunchingWithOptions
and place your audio code there.
EDIT:
As Kristopher Johnson has pointed out: it may be better to override viewDidAppear
or viewWillLoad
. But, viewDidLoad
has worked perfectly for me in the past.
thyrgle
2010-07-30 16:29:47
ah ok. yes, this particular sound file only needs to be played once after the page is loaded. will use didFinishLaunchingWithOptions. if i want some theme music, i will will you use method viewDidLoad. thanks.
yellahd
2010-07-30 17:25:51
Might `viewWillAppear` or `viewDidAppear` be a better method to override than `viewDidLoad`?
Kristopher Johnson
2010-07-30 17:26:01
@Kristopher Johnson: Nice catch. In fact, I'm probably going to start changing the way I've written some of my iPhone apps.
thyrgle
2010-07-30 17:46:58