1, System Sound Service Introduction:
The System Sound service provides an API to play sounds for no more than 30 seconds. It supports file formats that are limited, specifically only CAF, AIF, and WAV files that use PCM or IMA/ADPCM data. However, this function does not provide the ability to manipulate sounds and control the volume, so do not use the system sound service if you are creating specialized sounds for multimedia or games.
2, the system sound service supports the following three types:(1) Sound: Instantly play a simple sound file. If the phone is muted, the user cannot hear anything. (2) Reminder: Play a sound file, if the phone is set to mute or vibrate, then through the vibration to remind the user. (3) Vibration: Vibrate the phone without considering other settings.
3, using the sample (first in class to introduce Audiotoolbox)
(1) Sound playback
123456789101112 |
@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) Reminders
123456789101112 |
@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) Vibration
123456 |
@IBAction func systemvibration (sender: anyobject      //established Systemsoundid object      var soundid = systemsoundid (ksystemsoundid_vibrate) //vibration audioservicesplaysystemsound (Soundid) } |
Swift-use of the system sound service (play sounds, reminders, vibrations)