在android中合并两个mp3文件

时间:2015-08-13 09:43:05

标签: android mp3

我想在android中合并多个mp3文件但是例如我只用两个文件执行此操作:

 FileInputStream fileInputStream = new FileInputStream(soundFile.getAbsolutePath() + 0);
                FileInputStream fileInputStream1 = new FileInputStream(soundFile.getAbsolutePath() + 1);
                SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream, fileInputStream1);

                FileOutputStream fileOutputStream = new FileOutputStream(soundFile.getAbsolutePath());

                int temp;
                while ((temp = sequenceInputStream.read()) != -1) {
                    fileOutputStream.write(temp);
                }

                fileInputStream.close();
                fileInputStream1.close();
                sequenceInputStream.close();
                fileOutputStream.close();

我用" ttt.mp30"录制了两个声音。和" ttt.mp31"文件。然后我想把它合并到" ttt.mp3"

但是当我使用这段代码进行合并时,它只是创建ttt.mp3女巫玩ttt.mp30,但它没有播放ttt.mp31文件

问题是什么?

感谢

编辑:

如果我使用:

SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream1, fileInputStream);

绝对:

SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream, fileInputStream1);

ttt.mp3只播放ttt.mp31文件

修改:

记录选项:

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

1 个答案:

答案 0 :(得分:0)

 import java.io.*;
 public class TwoFiles
 {
public static void main(String args[]) throws IOException
{
    FileInputStream fistream1 = new FileInputStream("path\\1.mp3");  // first source file
    FileInputStream fistream2 = new FileInputStream("path\\2.mp3");//second source file
    SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
    FileOutputStream fostream = new FileOutputStream("path\\final.mp3");//destinationfile

    int temp;

    while( ( temp = sistream.read() ) != -1)
    {
        // System.out.print( (char) temp ); // to print at DOS prompt
        fostream.write(temp);   // to write to file
    }
    fostream.close();
    sistream.close();
    fistream1.close();
    fistream2.close();
}
}