NSString *path = nil;
path = [[NSBundle mainBundle] pathForResource:@"occasion"
ofType:@"aiff"];NSURL
* url = [NSURL URLWithString:path];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &soundID);
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &soundID);
AudioServicesPlaySystemSound(soundID);
receiveGiftCard
receiveGiftCard
-(void) playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"shake_sound_male" ofType:@"wav"];
if (path) {
//注册声音到系统
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&shake_sound_male_id);
AudioServicesPlaySystemSound(shake_sound_male_id);
// AudioServicesPlaySystemSound(shake_sound_male_id);//如果无法再下面播放,可以尝试在此播放
}
AudioServicesPlaySystemSound(shake_sound_male_id); //播放注册的声音,(此句代码,可以在本类中的任意位置调用,不限于本方法中)
// AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //让手机震动
}
本文介绍了如何在Objective-C中加载并播放音频文件,通过创建系统声音ID来实现声音的注册与播放,包括具体代码实现步骤及实例演示。
5127

被折叠的 条评论
为什么被折叠?



