//ide
// ViewController.m函數
// AudioToolbox音效播放url
//spa
// Created by dc008 on 15/12/28..net
// Copyright © 2015年 lin. All rights reserved.3d
//orm
#import "ViewController.h"get
#import <AudioToolbox/AudioToolbox.h>回調函數
@interface ViewController ()it
@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