[英]Processing/Java play WAV in a playlist
I know I've posted a similar question before but I can't seem to sort it. 我知道我之前也曾发布过类似的问题,但似乎无法对其进行排序。
I have wrote a program which opens a WAV file, loops it forever and displays a visualizer, which is fine. 我已经编写了一个程序来打开WAV文件,将其永久循环并显示可视化工具,这很好。
I can select many files with the following 我可以选择以下多个文件
chooser.setMultiSelectionEnabled(true);
However it only plays the first WAV file and keeps looping that. 但是,它仅播放第一个WAV文件并一直循环播放。
I am new to Java but am I right thinking that the selected WAV files need to be stored in an array and need to be called separately? 我是Java的新手,但我是否正确认为所选的WAV文件需要存储在数组中并且需要分别调用? As I would eventually want to load 25 WAV files around 30 seconds long each)
因为我最终想加载25个WAV文件,每个文件大约30秒长)
The code for choosing the files is below: 选择文件的代码如下:
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.setFileFilter(chooser.getAcceptAllFileFilter());
int returnVal = chooser.showOpenDialog(null);
minim = new Minim(this);
player = minim.loadFile(chooser.getSelectedFile().getAbsolutePath());
player.loop();
fft = new FFT(player.bufferSize(), player.sampleRate());
Also, click order is not important at the moment as the files selected will be randomly played one after the other, forever. 另外,单击顺序在当前并不重要,因为选择的文件将永远一个接一个地随机播放。
You need to use chooser.getSelectedFiles();
您需要使用
chooser.getSelectedFiles();
File[] selectedFiles = chooser.getSelectedFiles();
then inside a for-loop play the files. 然后在for循环中播放文件。
Now, if you want to loop over all songs, then you should have an upper while like below : 现在,如果您想循环播放所有歌曲,则应该有一个较高的时间,如下所示:
int loopTimes = 10;
while ( loopTimes > 0 )
{
for ( File file : selectedFiles )
{
player = minim.loadFile( file.getAbsolutePath() );
player.play();
}
loopTimes--;
}
I don't think the API for Minim::AudioPlayer
supports loop()
for multiple files. 我认为
Minim::AudioPlayer
的API不支持多个文件的loop()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.