gpt4 book ai didi

ios 添加音频到按钮

转载 作者:行者123 更新时间:2023-11-29 13:35:23 26 4
gpt4 key购买 nike

嗨,有人知道如何向按钮添加音频吗?我已经添加了框架,创建了一个放置声音的 Action ,但是当我按下按钮时没有声音播放?

这是我到目前为止所做的

-(void)buttonSound{


NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ButtonSound.mp3", [[NSBundle mainBundle] resourcePath]]];

NSError *error;
audioPlayer2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer2.numberOfLoops = -1;

[audioPlayer2 play];

}

- (IBAction)backToMenu:(id)sender {
[self buttonSound];
[self.navigationController popViewControllerAnimated:YES];
}

最佳答案

对于简短的系统声音,你应该使用类似的东西:

SystemSoundID sound;
CFURLRef alertURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), (CFStringRef)@"ButtonSound", CFSTR("mp3"), NULL);
OSStatus status = AudioServicesCreateSystemSoundID(alertURL, &sound);

AudioServicesPlayAlertSound(sound);

关于ios 添加音频到按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10702703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com