標籤:
系統聲音
1 // MARK: - 系統聲音 2 /*----- 系統聲音 ------*/ 3 @IBAction func systemSound() 4 { 5 //建立的SystemSoundID對象 6 var soundID: SystemSoundID = 0 7 8 //擷取音效檔地址 9 var path = NSBundle.mainBundle().pathForResource("SaoMa", ofType: "wav")10 11 //地址轉換12 var baseURL = NSURL(fileURLWithPath: path!)13 14 //賦值15 AudioServicesCreateSystemSoundID(baseURL , &soundID)16 17 //使用AudioServicesPlaySystemSound播放18 AudioServicesPlaySystemSound(soundID)19 }20 21 /*----- 系統提醒 ------*/22 @IBAction func systemAlert()23 {24 //建立的SystemSoundID對象25 var soundID: SystemSoundID = 026 27 //擷取音效檔地址28 var path = NSBundle.mainBundle().pathForResource("SaoMa", ofType: "wav")29 30 //地址轉換31 var baseURL = NSURL(fileURLWithPath: path!)32 33 //賦值34 AudioServicesCreateSystemSoundID(baseURL , &soundID)35 36 //使用AudioServicesPlayAlertSound播放37 AudioServicesPlayAlertSound(soundID)38 39 }40 41 /*----- 系統震動 ------*/42 @IBAction func systemVibration()43 {44 //建立的SystemSoundID對象45 var soundID = SystemSoundID(kSystemSoundID_Vibrate)46 47 //使用AudioServicesPlaySystemSound播放48 AudioServicesPlaySystemSound(soundID)49 }
ios開發——實用技術篇Swift篇&系統聲音