I have tried several options (many of them referenced from this post on SO and elsewhere) to get music to play on the iPhone simulator, but so far none of it has worked. I have tried -
- Unchecking, and then checking the box that says "Player user interface sound effects" in the Preferences > Sound option
- Going to Audio Midi Set Up, and changing the sample rate to 44100
- Ensuring that the output/input is both using the internal speakers
- Make sure that I imported
<AVFoundation/AVFoundation.h>
and added theAVFoundation.framework
to my linked frameworks. - Resetting iOS simulator using Reset Settings/Contents
- Restarting XCode, as well as as the computer
I have the following code in viewDidLoad
that is play the file gundam.mp3
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"gundam" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = 1;
player.volume = 0.9;
NSLog(@"The sound URL is %@", soundFileURL);
[player play];
The NSLog seems to be able to capture the file correctly: The sound URL is file://localhost/Users/zallanx/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/[...]/Missile%20Defender.app/gundam.mp3
I am unsure what I am doing incorrectly based on all the options I have tried, and would appreciate your help. Thanks!