0

Can some body explain how we can merge 2 mp3 files on iPhone? is it possible?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Kamleshwar
  • 2,967
  • 1
  • 25
  • 27
  • What do you mean 'merge' - overlay, or join? – Kirk Broadhurst Jan 07 '11 at 06:00
  • Merge means if i have two MP3 files fisrt is for 30 sec and second is for 20 sec. After merge there should be single file and as i play after it will be of 50 sec. first it will play 30 sec then 20 Sec(Singlle MP3) file. – Kamleshwar Jan 10 '11 at 12:30
  • Kamleshwar! I have exactly task as you have. Did you find your decision? Best regards. – EEduard Jul 10 '11 at 15:18
  • possible duplicate of [merge Audio files on iPhone](http://stackoverflow.com/questions/3359313/merge-audio-files-on-iphone) – Brad Larson Aug 05 '11 at 14:24

1 Answers1

0

Try the following code, it is for concatenation not for mixing. Haven't tested myself, but I will soon

NSMutableData *part1=[NSMutableData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"part1" ofType: @"mp3"]];
NSMutableData *part2=[NSMutableData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"part2" ofType: @"mp3"]];

[part1 appendData: part2];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *mp3file = [documentsDirectory stringByAppendingPathComponent: @"test.mp3"];

[part1 writeToFile: mp3file atomically:YES];

I think it should work

X Slash
  • 4,133
  • 4
  • 27
  • 35
Jim Huang
  • 401
  • 5
  • 9