0
private void initPlayer() throws MalformedURLException{
File dir = new File("../Railway PRS/Videos");
if (!dir.exists() && dir.isDirectory()){
//System.out.println("Cannot find audio source directory: " + dir);
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("File Not Found");
alert.setHeaderText("Video File Not Found: ");
alert.setContentText("Place the video folder onto the following location: ../Railway/Videos/File.mp4");
alert.showAndWait();
}
final List<MediaPlayer> players = new ArrayList<>();
File folder = new File("../Railway UTS/Videos");
File[] listofFiles = folder.listFiles();
File file;// = null;
for (i = 0; i < listofFiles.length; i++){
file = new File(listofFiles[i].getName());
//Media media = new Media(file.toURI().toURL().toString());
players.add(new MediaPlayer(new Media(file.toURI().toURL().toString())));
}
if (players.isEmpty()) {
//System.out.println("No audio found in " + dir);
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Audio File Not Found");
alert.setHeaderText("Audio File?");
alert.setContentText("Place the videos onto the following location: ../Railway/Videos/File.mp4");
alert.showAndWait();
}
mediaview = new MediaView(players.get(0));
//mediaview1 = new MediaView(players.get(0));
for (j = 0; j < players.size(); j++){
final MediaPlayer player = players.get(j);
final MediaPlayer nextPlayer = players.get((j + 1) % players.size());
player.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
mediaview.setMediaPlayer(nextPlayer);
nextPlayer.play();
//nextPlayer.setCycleCount(nextPlayer.INDEFINITE);
//player.setCycleCount(MediaPlayer.INDEFINITE);
}
});
}
mediaview.setMediaPlayer(players.get(0));
mediaview.getMediaPlayer().play();
basepane.getChildren().addAll(mediaview);
}
上記のコードは、ビデオ(プレイリスト)を1回再生します。私はそれがビデオ(プレイリスト)を連続して再生したい。サイクルカウントを無期限に設定すると、最初のビデオが繰り返され、2番目のビデオを再生すると、最初のビデオの音が聞こえます。アプリケーションが終了しない限り、プレイリストを継続的にノンストップで再生したいです。JavaFXで継続的にMediaPlayerでプレイリストを再生できません