【问题标题】:Merge two mp3 file in android在android中合并两个mp3文件
【发布时间】:2015-08-13 09:43:05
【问题描述】:

我想在 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);

【问题讨论】:

  • 也许这会对你有所帮助:stackoverflow.com/questions/18787409/…
  • 您不能合并两个音频文件,因为它们是原始数据。
  • @FrankN.Stein 我该怎么办?
  • 可能,两个文件一个接一个地播放? (最终捕获音频并将其保存为新的 mp3)。
  • @FrankN.Stein 如何使用 android 录制 mp3 文件?

标签: android mp3


【解决方案1】:
 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();
}
}

【讨论】:

    猜你喜欢
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    相关资源
    最近更新 更多