我有这种播放mp3的方法:
- (void) playSound:(NSString*)sound{
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
sound];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath error:nil];
[player prepareToPlay];
[player play];
}
每次调用此方法时,我都会得到一个新字符串“声音”,然后每次此 AVAudioplayer“播放器”时都必须分配;我想在我停止或完成时释放它……有可能吗?