我是使用 avadioplayer 的新手,每次播放声音时我似乎都有记忆。我无法弄清楚我在 Instrument 中缺少什么来摆脱它。这可能是误报吗?
视图控制器.h:
@interface ISpectatorViewController : UIViewController <UIAccelerometerDelegate>{
AVAudioPlayer *massCheerSoundID;
}
@property(nonatomic,retain) AVAudioPlayer * massCheerSoundID;
// ViewController.m
- (void)viewDidLoad {
NSString * filePath;
filePath = [[NSBundle mainBundle] pathForResource:@"massCheer" ofType:@"mp3"];
massCheerSoundID = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath ]error:nil];
}
- (void) playSound
{
if(massCheerSoundID.playing == false)
{
massCheerSoundID.currentTime = 0.0;
//leak here
[massCheerSoundID play];
}
}
- (void)dealloc {
[super dealloc];
[massCheerSoundID release];
}
我发现了问题所在。
我必须在界面上添加 AVAudioPlayerDelegate 因为我已经设置了 UIAccelerometerDelegate
@interface iSpectatorViewController: UIViewController<AVAudioPlayerDelegate>
并设置
massCheerSoundId.delegate = self