Q:

How to fix issues playing audio in xcode?

I have the following code in my viewcontroller. When I run, the audio doesn't play in the xcode simulator. Any advice on what I should do?
Also, I've saved anomaly.mp3 in the same directory (no sub-folders) as ViewController.m.
#import <AVFoundation/AVFoundation.h> //before viewDidLoad    

NSError * error = nil;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"anomaly"
                                     ofType:@"mp3"]];

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
                              initWithContentsOfURL:url
                              error:&error];
if (error){
    NSLog(@"error: %@", [error localizedDescription]);
}

NSLog(@"test");
[audioPlayer play];

A:

Try setting the audio player's volume.  You can also check the results of the "play" function, to see if things worked correctly.  The play function implicitly calls prepareToPlay.  This function can fail out for a number of reasons, irritatingly without any error object or message...
NSError * error = nil;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"anomaly"
                                     ofType:@"mp3"]];

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
                              initWithContentsOfURL:url
                              error:&error];
if (error){
    NSLog(@"error: %@", [error localizedDescription]);
} else {

    audioPlayer.volume = 50;

    if([audioPlayer play]) NSLog(@"Should be playing");
    else NSLog(@"Something weird happened"); //usually related to unavailable hardware
}

