2011-03-09 48 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提供的文檔中。

相關問題