如何将2个文件音频wav从raw组合到一个新的wav?

时间:2014-01-06 03:22:51

标签: android audio

我是android编程的新手,我想将2个文件音频wav组合到一个新的wav中,我得到了这个代码的答案

     import java.io.File;
import java.io.IOException;
import java.io.SequenceInputStream;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;

public class WavAppender {
    public static void main(String[] args) {
        String wavFile1 = "D:\\wav1.wav";
        String wavFile2 = "D:\\wav2.wav";

        try {
            AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1));
            AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));

            AudioInputStream appendedFiles = 
                            new AudioInputStream(
                                new SequenceInputStream(clip1, clip2),     
                                clip1.getFormat(), 
                                clip1.getFrameLength() + clip2.getFrameLength());

            AudioSystem.write(appendedFiles, 
                            AudioFileFormat.Type.WAVE, 
                            new File("D:\\wavAppended.wav"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

但是,上面的代码是针对java的,如果在android中转换怎么办?如何将原始的2个文件音频wav组合成一个新的wav?

谢谢,对不起我的英语。

1 个答案:

答案 0 :(得分:0)

private MediaPlayer mp;
mp = MediaPlayer.create(MyActivity.this,R.raw.monika);


 mp.setOnCompletionListener(new OnCompletionListener() {

 // play second wav file
 }
 });
 mp.start();
  

设置一个标志,以便第二个媒体播放器的onComplete lister不应该   玩了