Question: I am testing my app on my 3GS iPhone with iOS 4.2

I am using the following code which plays a sound in my IBAction. It works perfectly in the simulator (both iPad and iPhone) - I hear the sound. 

```
NSString *pathToMusicFile1 = [[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"mp3"];
NSError *error;
alarmSound = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile1] error:&error]; 
NSLog(@"Song1 Loaded");
if (alarmSound == nil) {
    NSLog(@"Error playing sound");
} else {
    alarmSound.numberOfLoops = 20;
    alarmSound.volume = 1.0;
    [alarmSound play];
}

```

I have everything declared properly (headers and frameworks etc) as I can hear the sound in the simulator. 

I have also checked that my phone is NOT in silent mode!! I hear other sounds from the generic iphone GUI. (example from a datepicker).

I have also cleaned all targets and deleted the app to reinstall. 

Any ideas what's wrong?!

Answer: 
It is **extremely important** to have the "audioPlayer" variable as a property. Otherwise with ARC, it gets released before it gets a chance to play!

It took me half an hour and some googling for this A-ha moment.

My sound works perfectly now!
have you tried `[NSURL URLWithString:pathToMusicFile1];` instead of `fileURLWithPath:`?