ios开发

iOS Audio Play-AudioServicesCreateSystem

转变为系统声音后播放

1. 在项目中引入   AudioToolbox.framework。

2. 在播放声音的类的头文件中   #import <AudioToolbox/AudioToolbox.h>

3. 声明成员变量

    SystemSoundID _pewPewSound;

4. 初始化变量

    NSString *pewPewPath = [[NSBundlemainBundle] pathForResource:@"button_click"ofType:@"mp3"];

    NSURL *pewPewURL = [NSURLfileURLWithPath:pewPewPath];

    AudioServicesCreateSystemSoundID((CFURLRef)pewPewURL, &_pewPewSound);

5. 播放声音

    AudioServicesPlaySystemSound(_pewPewSound);

6. 释放内存

    AudioServicesDisposeSystemSoundID(_pewPewSound);

这种声音是不会中断音乐播放。




评论