View Full Version : Playing Audio When App Starts

Apr 16, 2009, 10:42 AM
I have seen many apps that play a sort of "theme song" when they start up. I am able to play sounds when a button is pressed, but how to I get one to play at startup? It's a 30 second wav file, so I figured I could use the AudioServicesPlaySystemSound command. I put the following code in the viewDidLoad method of my View Controller. What am I missing?

CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle ();

themeSoundFileURLRef = CFBundleCopyResourceURL (mainBundle, CFSTR ("ThemeSong"), CFSTR ("wav"), NULL);
AudioServicesCreateSystemSoundID (themeSoundFileURLRef, &themeSoundFileObject);
AudioServicesPlaySystemSound (self.themeSoundFileObject);