Hey all,
So in an app I'm making I record a sound, and I have a sound built into the app. Once I record my sound, I would like to have the app merge, or compile the recorded sound and the sound already built into the app into 1 audio file which would be played back.
I have tried this
Code:
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"aif"];//piggy sound
//this gets the audio path from the recorded sound
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePathRecorded = [docsDir
stringByAppendingPathComponent:@"recorded.aif"];
//
NSURL *soundFilePathURL = [[NSURL alloc] initFileURLWithPath:path1];
NSData *sound1Data = [[NSData alloc] initWithContentsOfURL: soundFilePathURL];
NSURL *soundFilePathURL2 = [[NSURL alloc] initFileURLWithPath:soundFilePathRecorded];
NSData *sound2Data = [[NSData alloc] initWithContentsOfURL: soundFilePathURL2];
NSMutableData *sounds = [NSMutableData alloc];
[sounds appendData:sound1Data];
[sounds appendData:sound2Data];
[[NSFileManager defaultManager] createFileAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"compiledsound.aif"] contents:sounds attributes:nil];
NSString *compiledPath = [docsDir
stringByAppendingPathComponent:@"compiledsound.aif"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:compiledPath] error:NULL];
theAudio.delegate = self;
[theAudio play];
No audio plays when I try this. When I try to play the files individually however, they do.
Any ideas?
-iPhonig