0

我有这个声音块,但我想在 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 时,它开始出现错误。

4

1 回答 1

0

您应该可以在任何地方播放它而不会出现任何问题。只需将 soundID 设为实例变量即可。

请参考http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007328的SoundEffect类

于 2012-09-27T20:06:53.257 回答