iOS播放系统铃声

使用AudioServicesPlaySystemSound 这个接口来进行声音和震动的播放, 当然需要在工程中加入AudioToolBox.framework

1. 播放震动

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

2. 播放特定的声音

static SystemSoundID soundIDTest = 0;

NSString * path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"];
if (path) {
AudioServicesCreateSystemSoundID( (CFURLRef)[NSURL fileURLWithPath:path], &soundIDTest );

}

3.循环震动

AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate, NULL, NULL, systemAudioCallback, NULL);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

void systemAudioCallback()
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}

//播放
AudioServicesPlaySystemSound( soundIDTest );
//停止播放
AudioServicesDisposeSystemSoundID(_soundID);

查看系统音效地址:http://iphonedevwiki.net/index.php/AudioServices
部分声音说明:http://blog.csdn.net/like7xiaoben/article/details/9001806

你可能感兴趣的:(iOS播放系统铃声)