如何使用CDSoundEngine和Cocos2d 2.0从/ Documents /目录播放声音

时间:2013-04-17 15:29:07

标签: ios objective-c cocos2d-iphone nsdocumentdirectory

我正在使用CDSoundEngine录制声音并将其保存在users / Documents /目录中。它工作得很好......如果我去iPad模拟器的库,声音就在那里......

我的问题是他们不玩。如果我将声音文件复制到项目中,它就会播放。

我错过了什么?

 -(void) playRecording {

 //alternative approach
 //NSString *filePath = [NSURL fileURLWithPath: recorderFilePath];

 NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
 NSString *filePath = [url absoluteString];

 CCLOG(@"Playing the recorded audio ... %@",filePath); //correctly displays the path (with %20 for spaces) to /Documents/recording.caf

 CDSoundEngine *sse = [[CDAudioManager sharedManager] soundEngine];

 //[sse loadBuffer:1 filePath:@"recording.caf"]; //this works if the file is added to the main project

 [sse loadBuffer:1 filePath:filePath]; //this does not work

 //[sse loadBuffer:1 filePath:@"filePath"]; //this does not work

 [sse playSound:1 sourceGroupId: 0 pitch: 2.0f pan: 0.0f gain: 1.0f loop: NO];

 }

0 个答案:

没有答案