iOS 播放系統自帶鈴聲


播放聲音代碼例子

https://github.com/baitongtong/git-.git

 

給一個國外網址,蘋果系統鈴聲以及自定義鈴聲免登陸免費下載:http://www.zedge.net/ringtones/0-1-3-ios%207/?cursor=1..58

導入框架:

 

代碼:

 

 
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
 
@interface MsgPlaySound : NSObject
{
    SystemSoundID sound;//系統聲音的id 取值范圍為:1000-2000
}
- (id)initSystemShake;//系統 震動
- (id)initSystemSoundWithName:(NSString *)soundName SoundType:(NSString *)soundType;//初始化系統聲音
- (void)play;//播放
@end

  

 
 
#import "MsgPlaySound.h"
 
@implementation MsgPlaySound
 
- (id)initSystemShake
{
    self = [super init];
    if (self) {
        sound = kSystemSoundID_Vibrate;//震動
    }
    return self;
}
 
- (id)initSystemSoundWithName:(NSString *)soundName SoundType:(NSString *)soundType
{
    self = [super init];
    if (self) {
        NSString *path = [NSString stringWithFormat:@"/System/Library/Audio/UISounds/%@.%@",soundName,soundType];
        //[[NSBundle bundleWithIdentifier:@"com.apple.UIKit" ]pathForResource:soundName ofType:soundType];//得到蘋果框架資源UIKit.framework ,從中取出所要播放的系統聲音的路徑
        //[[NSBundle mainBundle] URLForResource: @"tap" withExtension: @"aif"];  獲取自定義的聲音
        if (path) {
            OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&sound);
            
            if (error != kAudioServicesNoError) {//獲取的聲音的時候,出現錯誤
                sound = nil;
            }
        }
    }
    return self;
}
 
- (void)play
{
    AudioServicesPlaySystemSound(sound);
}

  

 

 

apple系統默認聲音名稱說明:(此說明來自於http://bbs.weiphone.com/read-htm-tid-6262661.html

 

 

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---沒有找到匹配 
日歷 
alarm.caf--日歷提醒 
iPod Touch 1G 
sq_alarm.caf 
sq_beep-beep.caf 
sq_lock.caf 
sq_tock.caf 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM