use of javafx.scene.media.MediaException in project Media-Library by The-Rain-Goddess.
the class ApplicationWindow method setDataTableClickEvents.
private void setDataTableClickEvents() {
dataTable.setRowFactory(tv -> {
TableRow<MediaFile> row = new TableRow<>();
row.setOnMouseClicked(event -> {
try {
if (event.getButton() == MouseButton.SECONDARY) {
ContextMenu cMenu = new ContextMenu();
MenuItem remove = new MenuItem("Remove");
remove.setOnAction((ActionEvent ev) -> {
Main.getMasterData().remove(row.getItem().getUUID());
updateDataTable();
updateFileSystem();
});
cMenu.getItems().add(remove);
row.setOnContextMenuRequested(e -> cMenu.show(row, event.getScreenX(), event.getScreenY()));
} else {
if (event.getClickCount() == 1) {
System.out.println("Clicked");
System.out.println(row.getItem());
} else if (event.getClickCount() == 2) {
System.out.println("Playing: \n" + row.getItem());
File mediaFile = new File(row.getItem().getLibraryFilePath());
Media mediaToPlay = new Media(mediaFile.toURI().toString());
artistLabel.setText(row.getItem().getArtistName() + " - " + row.getItem().getAlbumName());
songLabel.setText(row.getItem().getSongName());
player.stop();
player = new MediaPlayer(mediaToPlay);
player.setAutoPlay(true);
updatePlayer();
}
}
} catch (MediaException e) {
Stage errorWindow = new Stage();
VBox componentLayout = new VBox();
Label errorLabel = new Label(e.getMessage());
VBox.setMargin(errorLabel, new Insets(10, 10, 10, 10));
componentLayout.getChildren().addAll(errorLabel);
Scene scene = new Scene(componentLayout);
errorWindow.setScene(scene);
errorWindow.show();
}
});
return row;
});
}
Aggregations