Android合并音频文件


Android合并音频文件

/**
  * 需求:将两个amr格式音频文件合并为1个
  * 注意:amr格式的头文件为6个字节的长度
  * @param partsPaths      各部分路径
  * @param unitedFilePath  合并后路径
  */
 public void uniteAMRFile(String[] partsPaths, String unitedFilePath) {
  try {
   File unitedFile = new File(unitedFilePath);
   FileOutputStream fos = new FileOutputStream(unitedFile);
   RandomAccessFile ra = null;
   for (int i = 0; i < partsPaths.length; i++) {
    ra = new RandomAccessFile(partsPaths[i], "r");
    if (i != 0) {
     ra.seek(6);
    }
    byte[] buffer = new byte[1024 * 8];
    int len = 0;
    while ((len = ra.read(buffer)) != -1) {
     fos.write(buffer, 0, len);
    }
   }
   ra.close();
   fos.close();
  } catch (Exception e) {
  }
 }

相关内容