我寻找了答案,但没有得到想要的答案。我想在iPhone项目上播放声音。我可以使用哪些文件类型?代码将如何?我对此一无所知,需要您的帮助吗?提前感谢...
最佳答案
首先在您的ViewController.h中,#import <AudioToolbox/AudioToolbox.h>
然后在您的ViewController.m中:
@property SystemSoundID theSound;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"Sound"
withExtension:@"mp3"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(soundURL), &_theSound);
}
- (IBAction)playSound
{
AudioServicesPlaySystemSound(_theSound);
}
- (void)dealloc
{
AudioServicesDisposeSystemSoundID(_theSound);
}
关于ios - 用xcode播放声音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24745935/