我有一个命令来运行音频文件列表,如下所示
public static void main(String[] args) {
File[] listFiles = new File(folder).listFiles();
ObservableList<Media> mediaList = FXCollections.observableArrayList();
for (File listFile : listFiles) {
mediaList.add(new Media(new File(listFile.getAbsolutePath()).toURI().toString()));
}
playMediaTracks(mediaList);
}
private static void playMediaTracks(ObservableList<Media> mediaList) {
if (!mediaList.isEmpty()) {
MediaPlayer mediaplayer = new MediaPlayer(mediaList.remove(0));
mediaplayer.play();
mediaplayer.setOnEndOfMedia(() -> {
playMediaTracks(mediaList);
});
}
}
操作代码不稳定,我有10个音频文件,但有时只有2个或3个文件被停止。但是该程序未报告错误,我不知道如何解决。请帮助我