Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-14-2011, 09:45 AM   #1 (permalink)
Registered Member
 
iphonig's Avatar
 
Join Date: Sep 2009
Location: United States
Posts: 73
iphonig is on a distinguished road
Default Combine 2 Audio Files into 1

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
__________________
Check Out All of Our Apps Here!
iphonig is offline   Reply With Quote
Old 07-15-2011, 01:20 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: PK
Posts: 27
d4devil is on a distinguished road
Default

I am not an expert with media in iphone but I did a little work a couple of months ago in audio recording.

First of all if you want to play both files at the same time then you should use AVPlayer (not AVAudioPlayer). AVPlayer work with AVPlayerItem. You can run multiple AVPlayerItems at the same time. See apple documentation for further information.

As you want to merge the file into 1 single file. You should look at AVAssetExportSession.

I hope this will give you direction for what you are looking for. Let me know if this helps u in any case.

Cheers.
d4devil is offline   Reply With Quote
Old 11-20-2011, 09:48 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 2
chucknorris is on a distinguished road
Default

I have the same problem as you?
Any ideas?
or Sample code??
chucknorris is offline   Reply With Quote
Reply

Bookmarks

Tags
audio files merge compile

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 367
9 members and 358 guests
apatsufas, chemistry, Kirkout, leostc, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0