简体   繁体   中英

Merge two audio files into one file

I really need some help. I want to merge two audio files and make a single audio file as .mp3 I think we can merge two files after getting their bytes but i am not sure it will work. i need some proper solution to do that

Hi look at below code might be help you

public void mergeParts ( ArrayList<String> nameList, String DESTINATION_PATH )
 {
  File[] file = new File[nameList.size()];
  byte AllFilesContent[] = null;

  int TOTAL_SIZE = 0;
  int FILE_NUMBER = nameList.size();
  int FILE_LENGTH = 0;
  int CURRENT_LENGTH=0;

  for ( int i=0; i<FILE_NUMBER; i++)
  {
   file[i] = new File (nameList.get(i));
   TOTAL_SIZE+=file[i].length();
  }

  try {
   AllFilesContent= new byte[TOTAL_SIZE]; // Length of All Files, Total Size
   InputStream inStream = null;

   for ( int j=0; j<FILE_NUMBER; j++)
   {
    inStream = new BufferedInputStream ( new FileInputStream( file[j] ));
    FILE_LENGTH = (int) file[j].length();
    inStream.read(AllFilesContent, CURRENT_LENGTH, FILE_LENGTH);
    CURRENT_LENGTH+=FILE_LENGTH;
    inStream.close();
   }

  }
  catch (FileNotFoundException e)
  {
   System.out.println("File not found " + e);
  }
  catch (IOException ioe)
  {
    System.out.println("Exception while reading the file " + ioe);
  }
  finally 
  {
   write (AllFilesContent,DESTINATION_PATH);
  }

  System.out.println("Merge was executed successfully.!");

 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM