iOS 分别用系统、媒体音量播放短音频、音效

#import 
//用系统音量播放
    SystemSoundID soundID;
    // 加载文件
    NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundName ofType:@"wav"]];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileURL), &soundID);

    // 播放短频音效
    AudioServicesPlayAlertSound(soundID);

    // 增加震动效果,如果手机处于静音状态,提醒音将自动触发震动
    AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
#import 
    //用媒体音量播放
    NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:soundName ofType:@"wav"]];

    self.audioplay = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];

    [self.audioplay play];

你可能感兴趣的:(iOS 分别用系统、媒体音量播放短音频、音效)