//
// ViewController.m
// AudioToolbox音效播放
//
// Created by dc008 on 15/12/28.
// Copyright © 2015年 lin. All rights reserved.
//
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 播放系统自带音效(1000-2000)
// AudioServicesPlaySystemSound(1005);
//1.要获取音效文件路径->文件url
NSString *audioFile = [[NSBundle mainBundle] pathForResource:@"videoRing" ofType:@"caf"];
NSLog(@"%@",audioFile);
NSURL *fileUrl =[NSURL fileURLWithPath:audioFile];
//2.获取声音ID
SystemSoundID soundID = 0;
//参数:音频文件url,声音id
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);
//如果需要在播放完成之后执行某些操作,可以调用下面方法注册一个回调函数
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, soundComplete, NULL);
//3.播放
AudioServicesPlaySystemSound(soundID);
}
void soundComplete(){
NSLog(@"播放完成");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end