1

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 -

  1. Unchecking, and then checking the box that says "Player user interface sound effects" in the Preferences > Sound option
  2. Going to Audio Midi Set Up, and changing the sample rate to 44100
  3. Ensuring that the output/input is both using the internal speakers
  4. Make sure that I imported <AVFoundation/AVFoundation.h> and added the AVFoundation.framework to my linked frameworks.
  5. Resetting iOS simulator using Reset Settings/Contents
  6. 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!

Community
  • 1
  • 1
daspianist
  • 5,336
  • 8
  • 50
  • 94
  • Have you reset the simulator, and closed and reopened XCode? (Simulator reset is more than just opening and closing, though; on the menu bar at the top of the screen go to iOS Simulator -> Reset Content and Settings) – WendiKidd Jul 27 '13 at 21:24
  • Thanks Wendi - I forgot to mention that I also did that as well (going into the simulator menu and reset content/settings). I also restarted my computer. – daspianist Jul 27 '13 at 21:47
  • Some things you can try... Have you tried using another sound file? Can you try calling [player prepareToPlay] to see if it helps? Does the app terminate before the sound file can play? Does the gundam.mp3 file play okay outside of the simulator? (on your mac) BTW, Audacity is great for modifying sounds http://audacity.sourceforge.net/ – Christopher Jul 27 '13 at 21:59
  • I am also having the same issue. I did everything as you did. – Shan Eapen Koshy Apr 04 '15 at 11:48

0 Answers0