Reputation: 309
trying to play a sound when app loads
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//sleep(2);
[NSThread sleepForTimeInterval:2.0];
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"austinpowers", CFSTR("wav"), NULL);
if (soundFileURLRef) {
CFStringRef url = CFURLGetString(soundFileURLRef);
}
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
it plays the sound, but only when the loading wallpaper (default.png) has gone. if someone can help me, or point me in the right direction
thanks
Upvotes: 1
Views: 221
Reputation: 35
This issue was solved for me by doing the following in the AppDelegate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
NSURL *clip = [[NSBundle mainBundle] URLForResource: @"intro" withExtension:@"caf"];
self.startupPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
[self.startupPlayer play];
}
This may work for you as well.
Upvotes: 0
Reputation: 21229
Do not use Default.png, but create your custom splash screen view controller where you can display your image and play sound.
Upvotes: 3