Search in sources :

Example 1 with MediaException

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;
    });
}
Also used : MediaFile(com.negativevr.media_library.files.MediaFile) Insets(javafx.geometry.Insets) MediaException(javafx.scene.media.MediaException) ActionEvent(javafx.event.ActionEvent) Media(javafx.scene.media.Media) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Scene(javafx.scene.Scene) TableRow(javafx.scene.control.TableRow) Stage(javafx.stage.Stage) MediaFile(com.negativevr.media_library.files.MediaFile) File(java.io.File) VBox(javafx.scene.layout.VBox) MediaPlayer(javafx.scene.media.MediaPlayer)

Aggregations

MediaFile (com.negativevr.media_library.files.MediaFile)1 File (java.io.File)1 ActionEvent (javafx.event.ActionEvent)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 ContextMenu (javafx.scene.control.ContextMenu)1 Label (javafx.scene.control.Label)1 MenuItem (javafx.scene.control.MenuItem)1 TableRow (javafx.scene.control.TableRow)1 VBox (javafx.scene.layout.VBox)1 Media (javafx.scene.media.Media)1 MediaException (javafx.scene.media.MediaException)1 MediaPlayer (javafx.scene.media.MediaPlayer)1 Stage (javafx.stage.Stage)1