2011-03-09 49 views
0

我使用的Xcode 4.2 我创建了一个功能,如下所示sequentialy播放声音剪辑的数组:我使用AudioServicesPlaySystemSound函数里面,我可以通过SystemSoundID变回调用程序

// - ------------------------------ // FUNCTION TO recite quad game messages // -------- ----------------------- void SayQuad(int pageNumber,NSMutableArray quadSounds []) NSString * fileName = [quadSounds objectAtIndex:pageNumber]; NSString * path = [[NSBundle mainBundle] pathForResource:fileName ofType:@“wav”]; SystemSoundID sayIt; ; NSURL * filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((CFURLRef)filePath,& sayIt); AudioServicesPlaySystemSound(sayIt);
} 现在基于用户操作,我想在声音剪辑结束之前取消声音剪辑。这可以通过以下方式完成: AudioServicesDisposeSystemSoundID(sayIt); 但是,变量“sayIt”需要传递回调用程序。 我是新来的,根本不知道该怎么做。 我曾尝试设置指针变量,但甚至无法让它们编译。

任何帮助将不胜感激。

回答

1

首先请注意正确格式化您的代码,以便我们可以轻松阅读它。它应该像这样的:

void SayQuad(int pageNumber, NSMutableArray quadSounds[]) { 

    NSString *fileName = [quadSounds objectAtIndex:pageNumber]; 
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"]; 
    SystemSoundID sayIt; 
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];  
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &sayIt); 
    AudioServicesPlaySystemSound(sayIt); 
} 

下一页请仔细阅读苹果公司提供:http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_AudioVideo_iPhone/_index.html 您正在使用的SystemSoundServices。要控制播放,您需要使用AVAudioPlayer或另一个像OpenAL。这全部写在Apple提供的文档中。

相关问题