views:

140

answers:

2

How would I play songs or make a splash screen for my cocoa app? I know it's a simple question but I am a complete noob when it comes to cocoa.

+4  A: 

You want to create an application delegate class and implement the -applicationWillFinishLaunching and -applicationDidFinishLaunching methods to display/hide your splash screen or start/stop your audio. You can connect an instance of this class as the application's delegate in Interface Builder in the project's MainMenu.xib.

Keep in mind that it's generally considered bad form to have to display a splash/load screen in Mac apps. If your app can start instantly and lazily load resources or load them in a background thread, it provides a much nicer experience for your users.

Barry Wark
+2  A: 

Barry is right, you have to get rid of this idea to use splash screens.. it's mainly a M$ Windows concept and it is kind of frustrating for the user to wait for the app to load itself, and I bet you won't load a thing and you just want to show a splash screen so you can feel important, but I'm telling you: apps with "marketing-only" splash screens are trash right from the beginning, because the user waits for absolutely nothing to load, and he/she will immediatelly get sick of seeing it every single time the app starts..

Now, about the songs.. I'll help you on this one, but I'm telling you again: it's useless, can't see the usefullness in having a sound play on every startup... so putting sound and a splash screen to your app startup will scare most users away, and your app won't made it!


So, to load a song you use the NSSound class like this:

NSSound *s = [[NSSound alloc] initWithContentsOfFile:songPath byReference:YES];

and then you can control it with the following methods:

[s play]
[s pause]
[s resume]
[s stop]
Woofy