title: How to merge two audio mp3 file in android?
body: <p>I'd like to merge two recorded audio files. Well, so far i searched a lot before posting here.
  Suppose if i merge first.mp3 and second.mp3 into merged.mp3 then merged.mp3 doesn't have data of second.mp3
  It is same as first.mp3.</p>
  
  <p>Here is my code snippets</p>
  
  <p>MainActivity Snippets  </p>
  
  <pre><code>Handler handler=new Handler();
                    handler.postDelayed(new Runnable() {
  
                      @Override
                      public void run() {
  
                          File first =  new File(path1);
                          File second = new File(path2);
                          String filepath = Environment.getExternalStorageDirectory().getPath();
                          File file = new File(filepath, "Dictatapp");
                          mergeSongs(new File(file.getAbsoluteFile()+"/mergedFile.mp3"), new File[] {first, second});
  
                      }
                  },2000);
  </code></pre>
  
  <p>Merge Function</p>
  
  <pre><code>private void mergeSongs(File mergedFile,File...mp3Files){
  
      try {
          FileInputStream fis1 = new FileInputStream(mp3Files[0]);
          FileInputStream fis2 = new FileInputStream(mp3Files[1]);
          Log.i("merge",mp3Files[0]+" "+mp3Files[1]);
          Toast.makeText(MainActivity.this, mp3Files[0].toString()+mp3Files[1].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();
          }
  
  }
  </code></pre>