0

I am trying to play two .wav files in my appllication, but i am only able to play the first wav file , the second file is not at all playing.

I have added the AudioToolbox framework. In my .h file i have included the Audiotoolbox.h file and has the following declarations

//Beep Sound
SystemSoundID   soundFileObject;
SystemSoundID   recycleFileObject;

In my .m file i am registering both the wav files as following

CFURLRef soundFileURLRef = CFBundleCopyResourceURL (CFBundleGetMainBundle (),CFSTR ("Beep"),CFSTR ("wav"),NULL );
AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject );

CFURLRef soundFileURLRef2 = CFBundleCopyResourceURL (CFBundleGetMainBundle (),CFSTR ("Recycle"),CFSTR ("wav"),NULL );
AudioServicesCreateSystemSoundID (soundFileURLRef2,&recycleFileObject );

And i have written two methods for playing each file individually.

-(void)playBeepSound
{
    NSLog(@"Beep sound called : %d", soundFileObject);
    AudioServicesPlaySystemSound (soundFileObject);
}


-(void)playRecycleSound
{
    NSLog(@"Recycle sound called : %d", recycleFileObject);
    AudioServicesPlaySystemSound (recycleFileObject);
}

But i am only able to play the Beep sound , but not the second sound wav file.

What is the error ???

Thanks

4

1 回答 1

0

如果我是你,我会将音频工具箱代码包装在一个类中,这样你就可以分解出通用代码并更舒适地播放声音(示例代码)。这也可以解决您的问题,因为它似乎是某个地方的一个小错字——您给我们的示例代码看起来不错。(您是否尝试记录所有内容?没有空值,所有内容都按预期调用?您是否尝试同时播放两种声音,或者它们之间是否存在延迟?哪个声音先运行有关系吗?)

于 2010-04-19T17:06:03.060 回答