Second call to AVAudioPlayer -> EXC_BAD_ACCESS (code posted, what did I miss?)
I'm using this code to play a different mp3 files with every call开发者_JAVA技巧. 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?
[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.
精彩评论