How to release audio properly? (AVAudioPlayer)
Posted
by
Aluminum
on Stack Overflow
See other posts from Stack Overflow
or by Aluminum
Published on 2011-01-09T21:24:03Z
Indexed on
2011/01/12
3:54 UTC
Read the original article
Hit count: 202
Hello everyone!
I need help with my iOS
application ^^,. I want to know if I'm releasing AVAudioPlayer
correctly.
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
© Stack Overflow or respective owner