Reputation: 39
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.
Upvotes: 2
Views: 102
Reputation:
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.
Upvotes: 1