简体   繁体   English

java(Android)中 AudioInputStream 的替代 class 是什么?

[英]what is the alternative class for AudioInputStream in java (Android)?

About a year ago I started to built an application for android.大约一年前,我开始为 android 构建应用程序。 Now when I try to run it I get an exception about AudioInputStream class, After a short research that I did using GOOGLE I found out that android doesn't support this class anymore... Is their any alternative for it?现在,当我尝试运行它时,我得到了一个关于 AudioInputStream class 的异常,经过我使用 GOOGLE 进行的简短研究后,我发现 android 不再支持这个 class 了吗?

This is the code that I wrote:这是我写的代码:

    private void merge2WavFiles(String wavFile1, String wavFile2, String newWavFilePath) {

    try {
        File wave1 = new File(wavFile1);
        if(!wave1.exists())
            throw new Exception(wave1.getPath() + " - File Not Found");
        AudioInputStream clip1 = AudioSystem.getAudioInputStream(wave1);
        AudioInputStream clip2 = AudioSystem.getAudioInputStream(new File(wavFile2));

        AudioInputStream emptyClip = 
            AudioSystem.getAudioInputStream(new File(emptyWavPath));            

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

        clip1 = appendedFiles;

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

        AudioSystem.write(appendedFiles, AudioFileFormat.Type.WAVE, new File(newWavFilePath));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I also have similar problems to yours while developing a frequency generating methods set on android, so I digged everywhere alot in the APIs of android references and java se 1.7 docs.在开发在 android 上设置的频率生成方法时,我也遇到了与您类似的问题,因此我在 android 参考和 java se 1 的 API 中到处挖掘。 But there do not exist easily-exchangeable alternatives of class AudioInputStream and even also class AudioSystem found in your code.但是在您的代码中不存在 class AudioInputStream 甚至 class AudioSystem 的易于更换的替代品。 If you want use your legacy you may have to revise and refactor several items.如果你想使用你的遗产,你可能需要修改和重构几个项目。 In my cases, I used InputStream and ByteArrayInputStream (java.io) for that, and recording and systematic some actions will be managed by AudioRecord and AudioManager (android.media).在我的例子中,我使用了 InputStream 和 ByteArrayInputStream (java.io),记录和系统化的一些动作将由 AudioRecord 和 AudioManager (android.media) 管理。 Note that AudioFormat in android and java7 are different its internal characteristics.注意android和java7中的AudioFormat其内部特性不同。 If I cleared my issues upon the audio manipulation, I will attach a piece of sample code for you.如果我在音频处理时解决了我的问题,我将为您附上一段示例代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM