首页 > 代码库 > IOS 播放音频
IOS 播放音频
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