我试着按照这个链接:
但混合音频文件后,sdcard上的文件(mixed.wav)无法播放,我不知道为什么.你能帮助我吗?.非常感谢你 ..
这是我的代码:
公共类MainActivity扩展Activity {
public static final int FREQUENCY = 44100;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
mixSound();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void mixSound() throws IOException {
AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, 44100, AudioTrack.MODE_STREAM);
InputStream in1 = getResources().openRawResource(R.raw.media_b);
InputStream in2 = getResources().openRawResource(R.raw.media_c);
byte[] arrayMusic1 = null;
arrayMusic1 = new byte[in1.available()];
arrayMusic1 = createMusicArray(in1);
in1.close();
byte[] arrayMusic2 = null; …Run Code Online (Sandbox Code Playgroud) 我的音频文件很少:
我需要的是找到一种方法在f_1的特定部分混合(合并)f2和f3(即等于6秒的位置)
我正在看音频示例,但它们对我没什么帮助,所以任何想法\参考\文档可能会有所帮助?
非常感谢!
我有一个我想要合并的文件数组.这是我尝试过的,但它没有用.
public static void joinf(File f1, File f2){
try{
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2,true);
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
in.close();
out.close();
System.out.println("File copied.");
}
catch(FileNotFoundException ex){
System.out.println(ex.getMessage() + " in the specified directory.");
System.exit(0);
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
public void pro(File a,File[]b){
for(int i=0;i<b.length;i++){
joinf(a,b[i]);
}
}
Run Code Online (Sandbox Code Playgroud)