iOS 多媒体(3)播放系统声音

添加AudioToolbox.framework库

- (IBAction)btnPalyer:(id)sender {
    NSString *path=[[NSBundle mainBundle]pathForResource:@"dog" ofType:@"caf"];
    NSURL *url=[NSURL fileURLWithPath:path];
    UInt32 soundID;
    //将url所在的音频文件注册为系统声音,soundID音频ID标示该音频
    AudioServicesCreateSystemSoundID((CFURLRef)url, &soundID);
    //播放音频
    AudioServicesPlaySystemSound(soundID);
  
    //震动
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    
}


你可能感兴趣的:(iOS 多媒体(3)播放系统声音)