IOS 声音控制

来源:互联网 发布:星推网络招聘 编辑:程序博客网 时间:2024/05/23 18:25

1. 改变声音音量使用:

MPVolumeView:controls every sound within the app;

[[MPMusicPlayerController applicationMusicPlayer] setVolume:volumeValue]: controls audio volume;


2. 播放声音:

NSURL *url = [NSURLURLWithString:@"/System/Library/Audio/UISounds/begin_video_record.caf"];

AVAudioPlayer *audio = [[AVAudioPlayeralloc]initWithContentsOfURL:url error:nil];

[audio play];


3. 播放系统声音(这种播放声音的音量无法改变)

    SystemSoundID myAlertSound;

    NSURL *url = [NSURL URLWithString:@"/System/Library/Audio/UISounds/begin_video_record.caf"];

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &myAlertSound);    

    AudioServicesPlaySystemSound(myAlertSound);


原创粉丝点击