使用AudioToolbox按一个按钮后,我播放了这个声音。
-(void) onButtonPressSound {
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"m4a"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
}
按下此按钮后,如何让它播放2个声音而不是一个,一个接一个?
谢谢,
答案 0 :(得分:2)
有两种方法可以做到这一点: 第一个:像我这样懒惰的人:) 发出一个接一个播放2个声音的声音。 另一个:
SystemSoundID receiveMessageSound1;
SystemSoundID receiveMessageSound2;
NSString *sendPath1 = [[NSBundle mainBundle] pathForResource:@"Music1" ofType:@"wav"];
CFURLRef baseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:sendPath];
AudioServicesCreateSystemSoundID(baseURL, &receiveMessageSound1);
AudioServicesPlaySystemSound(receiveMessageSound1);
NSString *sendPath2 = [[NSBundle mainBundle] pathForResource:@"Music2" ofType:@"wav"];
baseURL = (__bridge CFURLRef)[NSURL fileURLWithPath:sendPath2];
AudioServicesCreateSystemSoundID(baseURL, &receiveMessageSound2);
AudioServicesPlaySystemSound(receiveMessageSound2);
希望这有帮助。