views:

50

answers:

1

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
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
Might `viewWillAppear` or `viewDidAppear` be a better method to override than `viewDidLoad`?
Kristopher Johnson
@Kristopher Johnson: Nice catch. In fact, I'm probably going to start changing the way I've written some of my iPhone apps.
thyrgle