[英]How to mix two audio files in Android and then save؟
I have two audio files in MP3 format inside the user's phone How can I mix these two sounds?我在用户手机中有两个 MP3 格式的音频文件,如何混合这两个声音? That is, I put these two sounds on top of each other and mix them, and then save the final sound in the user's phone I looked everywhere but found nothing
也就是我把这两种声音叠加在一起混合,然后把最终的声音保存在用户的手机里我到处找了找也没找到
this is my code:这是我的代码:
private void mergeSongs(File mergedFile,File...mp3Files){
FileInputStream fisToFinal = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mergedFile);
fisToFinal = new FileInputStream(mergedFile);
for(File mp3File:mp3Files){
if(!mp3File.exists())
continue;
FileInputStream fisSong = new FileInputStream(mp3File);
SequenceInputStream sis = new SequenceInputStream(fisToFinal, fisSong);
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fisSong.read(buf)) != -1;)
fos.write(buf, 0, readNum);
} finally {
if(fisSong!=null){
fisSong.close();
}
if(sis!=null){
sis.close();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(fos!=null){
fos.flush();
fos.close();
}
if(fisToFinal!=null){
fisToFinal.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
I have to finish the project today......help me!我今天必须完成这个项目……帮帮我!
You could use SequenceInputStream.您可以使用 SequenceInputStream。 https://docs.oracle.com/javase/8/docs/api/java/io/SequenceInputStream.html
https://docs.oracle.com/javase/8/docs/api/java/io/SequenceInputStream.html
FileInputStream fileInputStream1 = new FileInputStream("/sdcard/mp3/sound1.mp3");
FileInputStream fileInputStream2 = new FileInputStream("/sdcard/mp3/sound2.mp3");
SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream1, fileInputStream2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.