标签:
1,系统声音服务介绍:
1
|
import AudioToolbox |
(1)声音播放
1
2
3
4
5
6
7
8
9
10
11
12
|
@IBAction func systemSound(sender: AnyObject ) { //建立的SystemSoundID对象 var soundID: SystemSoundID = 0 //获取声音地址 var path = NSBundle .mainBundle().pathForResource( "msg" , ofType: "wav" ) //地址转换 var baseURL = NSURL (fileURLWithPath: path!) //赋值 AudioServicesCreateSystemSoundID (baseURL, &soundID) //播放声音 AudioServicesPlaySystemSound (soundID) } |
(2)提醒
1
2
3
4
5
6
7
8
9
10
11
12
|
@IBAction func systemAlert(sender: AnyObject ) { //建立的SystemSoundID对象 var soundID: SystemSoundID = 0 //获取声音地址 var path = NSBundle .mainBundle().pathForResource( "msg" , ofType: "wav" ) //地址转换 var baseURL = NSURL (fileURLWithPath: path!) //赋值 AudioServicesCreateSystemSoundID (baseURL, &soundID) //提醒(同上面唯一的一个区别) AudioServicesPlayAlertSound (soundID) } |
(3)振动
1
2
3
4
5
6
|
@IBAction func systemVibration(sender: AnyObject ) { //建立的SystemSoundID对象 var soundID = SystemSoundID (kSystemSoundID_Vibrate) //振动 AudioServicesPlaySystemSound (soundID) } |
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4843381.html