我有这个声音块,但我想在 didloader 中预加载大部分内容,然后调用 AudioServicesPlaySystemSound(soundID);
节目内
-(void)buttonpress{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"chalkfreeze", CFSTR ("mp3"), NO);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
提供编码
-(void)viewDidloader
{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"chalkfreeze", CFSTR ("mp3"), NO);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
}
- (void)buttonpress
{
AudioServicesPlaySystemSound(soundID);
}
所以类似于上面的代码,但它不起作用,当我尝试在 .h 文件中声明 soundID 时,它开始出现错误。