Adding two Mp3 files in Android

How can I add two audio files in android. I tried this, but it does not work. Pls give me soln.I need to combine files with sdcard that ts A.mp3 and B.mp3. When I combine the concatenate method calls, I want both of them to be as one file in the SD card, i.e. C.mp3 ........

File original= new File("/mnt/sdcard/A.mp3"); File temp=new File("/mnt/sdcard/B.mp3"); Log.i("...............",""+path); try { File outFile= new File("/mnt/sdcard/C.mp3 "); DataOutputStream out=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outFile))); // FileOutputStream out=new FileOutputStream(outFile); //OutputStream out = new FileOutputStream(original,true); int m,n; m=(int) temp.length(); n=(int) original.length(); byte[] buf1 = new byte[m]; byte[] buf2 = new byte[n]; byte[] outBytes = new byte[m+n]; DataInputStream dis1=new DataInputStream( new BufferedInputStream(new FileInputStream(original))); DataInputStream dis2=new DataInputStream( new BufferedInputStream(new FileInputStream(temp))); dis1.read(buf1, 0, m); dis1.close(); dis2.readFully(buf2, 0, n); dis2.close(); out.write(buf1); out.write(buf2); out.flush(); //in.close(); out.close(); System.out.println("File copied."); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

I need to combine the file A.mp3, B.mp3 with C.mp3 ....

+1
java android arrays android-file android-mediaplayer
source share
2 answers

In addition to the knowbody answer, you can refer to the mp3 file format specification for more information HERE and HERE .

There are many things you should consider when stitching two mp3 files. It’s less to say that they must be encoded with the same program, with the same settings, or if it is a voice that should be taken from the same microphone, with the same settings, etc.

+2
source share
 import java.io.*; public class TwoFiles { public static void Main(String args[]) throws IOException { FileInputStream fistream1 = new FileInputStream("C:\\Temp\\1.mp3"); FileInputStream fistream2 = new FileInputStream("C:\\Temp\\2.mp3"); SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2); FileOutputStream fostream = new FileOutputStream("C:\\Temp\\final.mp3"); int temp; while( ( temp = sistream.read() ) != -1) { fostream.write(temp); } fostream.close(); sistream.close(); fistream1.close(); fistream2.close(); } } 

I hope this is clear.

0
source share

All Articles