Reputation: 5212
About a year ago I started to built an application for 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?
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();
}
}
Upvotes: 4
Views: 5247
Reputation: 26
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. But there do not exist easily-exchangeable alternatives of class AudioInputStream and even also class AudioSystem found in your code. 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). Note that AudioFormat in android and java7 are different its internal characteristics. If I cleared my issues upon the audio manipulation, I will attach a piece of sample code for you.
Upvotes: 1