Java音频API在循环后停止播放

Java音频API在循环后停止播放,java,audio,playback,Java,Audio,Playback,我已经写了这段代码,它将音频循环一次,然后文件继续播放 public void playNextSecond(long startFrame) { //Get the number of frames for one second float sampleRate = audioStream.getFormat().getSampleRate(); //Set the current playback time to the start of the loop sect

我已经写了这段代码,它将音频循环一次,然后文件继续播放

public void playNextSecond(long startFrame) {
    //Get the number of frames for one second
    float sampleRate = audioStream.getFormat().getSampleRate();

    //Set the current playback time to the start of the loop section
    clip.setFramePosition((int)startFrame);

    //Set up the looping segment
    clip.setLoopPoints((int)startFrame, (int)(startFrame + sampleRate));

    //Loop one time
    clip.loop(1);
}

我想在循环完成后停止播放。有什么办法可以这样做吗?或者,是否仍要播放到特定帧?

显示的代码看起来应该播放一秒钟。如果没有,我很惊讶。播放特定帧的一种方法是边走边计数帧,这需要使用SourceDataLine作为输出。下面链接中的第一个代码示例(Java教程,使用文件和格式转换器)展示了一种计算帧的方法。“为什么?这只会播放整个文件。我想播放一个片段,只播放那个片段,而不播放整个文件”:你在这里什么都不付钱,你明白吗??所以现在就开始干你的事吧