简体   繁体   English

对代码语句Java的怀疑

[英]Doubts about code statement Java

Can you explain the following code ..please? 您能解释下面的代码吗? Especially this code statement 特别是这段代码声明

AudioInputStream joinFiles = new AudioInputStream(new SequenceInputStream(
            clip1, clip2), clip1.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. AudioInputStream在其构造函数中采用SequenceInputStream ,格式和长度。

clip1.getFormat() just takes the format from clip1, and passes it to the new stream. clip1.getFormat()仅采用clip1的格式,并将其传递给新的流。 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. clip1.getFrameLength() + clip2.getFrameLength()仅声明新流的长度应为两个剪辑长度的总和。

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: 该代码似乎没有什么奇怪的-我认为您正在忽略SequenceInputStream部分,该部分执行以下操作:

A SequenceInputStream represents the logical concatenation of other input streams. SequenceInputStream表示其他输入流的逻辑串联。 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. 它从输入流的有序集合开始,从第一个开始读取,直到到达文件末尾,然后从第二个开始读取,依此类推,直到在最后一个包含的输入流中到达文件末尾。

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

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