我需要幫助我的iOS
應用程序^^ ,.我想知道我是否正確釋放AVAudioPlayer
。如何正確釋放音頻? [AVAudioPlayer]
MyViewController.h
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController
{
NSString *Path;
}
- (IBAction)Playsound;
@end
MyViewController.m
#import <AVFoundation/AVAudioPlayer.h>
#import "MyViewController.h"
@implementation MyViewController
AVAudioPlayer *Media;
- (IBAction)Playsound
{
Path = [[NSBundle mainBundle] pathForResource:@"Sound" ofType:@"wav"];
Media = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:Path] error:NULL];
[Media play];
}
- (void)dealloc
{
[Media release];
[super viewDidUnload];
}
@end
在dealloc方法,你應該調用[超級的dealloc]而不是[超級viewDidUnload。之前我沒有注意到,所以我編輯了我的帖子。 – yabada 2011-01-10 00:14:22