代碼已經上傳github,喜歡的朋友請點一個贊,您的點贊是對我最大的支持,謝謝:GitHub - 1806339272/audioSound: Call the system mobile phone ring
1、在工程中導入AudioToolbox.frame
2、創建一個JFMyPlayerSound類,主要代碼如下
2.1、系統震動
-(id)initSystemShake
{
self= [superinit];
if(self) {
sound=kSystemSoundID_Vibrate;//震動
}
return self;
}
2.2、初始化系統聲音
-(id)initSystemSoundWithName:(NSString*)soundName SoundType:(NSString*)soundType
{
self= [superinit];
if(self) {
NSString*path = [NSStringstringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",soundName,soundType];
if(path) {
OSStatuserror =AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path],&sound);
if(error !=kAudioServicesNoError) {//獲取的聲音的時候,出現錯誤
NSLog(@"靜音");
sound=nil;
}
}
return self;
}
2.3、播放
- (void)play
{
AudioServicesPlaySystemSound(sound);
}
3、在需要調用鈴聲的工程中,引入#import“JFMyPlayerSound.h",直接創建JFMyPlayerSound
3.1、設置震動
self.myPlaySounde= [[JFMyPlayerSoundalloc]initSystemShake];
3.2、設置鈴聲
self.myPlaySounde= [[JFMyPlayerSoundalloc]initSystemSoundWithName:nameSoundType:@"caf"];
3.3、播放
[self.myPlaySoundeplay];
4、判斷手機是否開啟靜音模式
將文件夾sound直接拷貝到工程中即可
實現下面方法:
[[RBDMuteSwitchsharedInstance]setDelegate:self];
[[RBDMuteSwitchsharedInstance]detectMuteSwitch];
添加下面方法來判斷是否是靜音模式
-(void)isMuted:(BOOL)muted
5、蘋果系統默認聲音名稱說明:
1.聲音格式是MP3或m4r的需要轉成caf格式(可先轉成aif , aiff,然后修改后綴)
2.路徑在/System/Library/Audio/UISounds 里,需要更改的可以根據以下列表進行替換
3詳細列表:
信息
ReceivedMessage.caf--收到信息,僅在短信界面打開時播放。
sms-received1.caf-------三全音
sms-received2.caf-------管鐘琴
sms-received3.caf-------玻璃
sms-received4.caf-------圓號
sms-received5.caf-------鈴聲
sms-received6.caf-------電子樂
SentMessage.caf--------發送信息
郵件
mail-sent.caf----發送郵件
new-mail.caf-----收到新郵件
電話
dtmf-0.caf----------撥號面板0按鍵
dtmf-1.caf----------撥號面板1按鍵
dtmf-2.caf----------撥號面板2按鍵
dtmf-3.caf----------撥號面板3按鍵
dtmf-4.caf----------撥號面板4按鍵
dtmf-5.caf----------撥號面板5按鍵
dtmf-6.caf----------撥號面板6按鍵
dtmf-7.caf----------撥號面板7按鍵
dtmf-8.caf----------撥號面板8按鍵
dtmf-9.caf----------撥號面板9按鍵
dtmf-pound.caf---撥號面板#按鍵
dtmf-star.caf------撥號面板*按鍵
Voicemail.caf-----新語音郵件
輸入設備聲音提示
Tock.caf-----------------------點擊鍵盤
begin_record.caf-----------開始錄音
begin_video_record.caf--開始錄像
photoShutter.caf------------快門聲
end_record.caf--------------結束錄音
end_video_record.caf-----結束錄像
其他
beep-beep.caf--充電、注銷及連接電腦
lock.caf------------鎖定手機
shake.caf---------“這個還沒搞清楚”
unlock.caf--------滑動解鎖
low_power.caf--低電量提示
語音控制
jbl_ambiguous.caf--找到多個匹配
jbl_begin.caf------等待用戶的輸入
jbl_cancel.caf-----取消
jbl_confirm.caf----執行
jbl_no_match.caf---沒有找到匹配