Can you explain the following code ..please? Especially this code statement
AudioInputStream joinFiles = new AudioInputStream(new SequenceInputStream(
clip1, clip2), clip1开发者_如何学JAVA.getFormat(), clip1.getFrameLength()
+ clip2.getFrameLength());
My understanding is that the join operation can only be done if the files have the same length, is that correct?
What puzzles me is this:
clip1.getFormat(), clip1.getFrameLength()
+ clip2.getFrameLength());
Here's the complete code:
AudioInputStream clip1 = AudioSystem.getAudioInputStream(song1);
AudioInputStream clip2 = AudioSystem.getAudioInputStream(song2);
AudioInputStream joinFiles = new AudioInputStream(new SequenceInputStream(
clip1, clip2), clip1.getFormat(), clip1.getFrameLength()
+ clip2.getFrameLength());
AudioSystem.write(joinFiles, AudioFileFormat.Type.WAVE, outfile);
thank you , Ulrike
AudioInputStream
takes a SequenceInputStream
, a format, and a length in its constructor.
clip1.getFormat()
just takes the format from clip1, and passes it to the new stream. The two files obviously have to be of the same format for this to work.
clip1.getFrameLength() + clip2.getFrameLength()
just states that the new stream should be of the length that is the sum of the two clip lengths.
I don't know that the two files need to have the same; I don't see why that should be the case.
There doesn't seem to be anything odd about that code - I think you are overlooking the SequenceInputStream part, which does the following:
A
SequenceInputStream
represents the logical concatenation of other input streams. It starts out with an ordered collection of input streams and reads from the first one until end of file is reached, whereupon it reads from the second one, and so on, until end of file is reached on the last of the contained input streams.
精彩评论