1,播放短音频
#import <AudioToolbox/AudioToolbox.h>
#import "GLYViewController.h"
static void completionCallback(SystemSoundID mySSID)
{
AudioServicesPlaySystemSound(mySSID);
}
@interface GLYViewController ()
@end
@implementation GLYViewController
SystemSoundID crash;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL* crashUrl = [[NSBundle mainBundle] URLForResource:@"crash"
withExtension:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)crashUrl, &crash);
AudioServicesAddSystemSoundCompletion(crash, NULL, NULL, (void *)completionCallback, NULL);
}
- (IBAction)play:(id)sender {
AudioServicesPlayAlertSound(crash);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
原文地址:http://www.cnblogs.com/guanliyang/p/3809682.html