Android : how to merge two mp3 files and stored it into sdcard?

on Monday, October 13, 2014


I tried to merge two mp3 file and I followed using below urls, How to merge two audio mp3 file in android? Concatenating MP3 files How to merge two mp3 files into one (combine/join) Join two WAV files from Java?


I want to merge two mp3 files.


example :


File1 has 25 second long.


File2 has 15 second long.


then output file should be like 25 second long and output file must contains both files audio starting from 0 second.


Here file 1 and file2 is stored in sdcard and both file formate is .mp3 and merged file is also mp3


please find the below code.



File file1=new File(fileName);
File file2=new File(fileName2);
File mergedfile=new File(mergedFile);
mergeSongs(mergedfile, file1,file2);


mergeSongs Function is.



private void mergeSongs(File mergedFile,File file1,File file2){

try {
FileInputStream fis1 = new FileInputStream(file1);
FileInputStream fis2 = new FileInputStream(file2);
Log.i("merge",file1+" "+file1);
Toast.makeText(this, file1.toString()+file2.toString(), Toast.LENGTH_LONG).show();
SequenceInputStream sis = new SequenceInputStream(fis1,fis2);

if(!mergedFile.exists()){
mergedFile.createNewFile();}

FileOutputStream fos = new FileOutputStream(mergedFile);

int temp;

while ((temp = sis.read())!= -1){

fos.write((byte)temp);

}

fis1.close();
fis2.close();
sis.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}

}


In merged file I got only file1 data only


i m not able to understand where is the problem.


is this possible using mediaplayer?


0 comments:

Post a Comment