views:

85

answers:

1

I'm using this code to play a different mp3 files with every call. The first time through works great. The second time crash, as indicated below.

.h

AVAudioPlayer *player;
@property (nonatomic, retain) AVAudioPlayer *player;

.m

-(void)load:(NSURL *)aFileURL {
 if (aFileURL) {

  AVAudioPlayer *newPlayer =
  [[AVAudioPlayer alloc] initWithContentsOfURL: aFileURL
                      error: nil];

  [aFileURL release];
  self.player = newPlayer; // CRASHES HERE EXC_BAD_ACCESS with second MP3a
  [newPlayer release];

  [self.player prepareToPlay];
  [self.player setDelegate:self];
 }   
}

I know I must have missed something, any ideas?

A: 
 [aFileURL release];

You should not -release the url in -load:, since that function is not an owner. The EXC_BAD_ACCESS is probably due to double-release of that URL.

Try to remove this line.

KennyTM
That's how you know you've been staring at the screen too long!!! Totally forgot about that. Jordan time-to-take-a-break, Much Appreciated!
Jordan