Skip to content

Commit 3ef4f5a

Browse files
committed
Fixed error when playing with Double-Click on the TableView.
1 parent 433f4e1 commit 3ef4f5a

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

Server/src/main/java/viewmodels/MainWindowViewModel.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,7 @@ public void onButtonPlayPauseClicked() {
218218
this.mediaPlayer.pause();
219219
this.musicStreamController.stop();
220220
} else if (this.getSelectedSong() != null) {
221-
this.logger.info("Trying to play: " + this.getSelectedSong().getTitle());
222-
223-
if(this.getSelectedSong() != null) {
224-
// Start streaming...
225-
this.logger.info("Streaming the new song: " + this.getSelectedSong().getTitle());
226-
try {
227-
this.musicStreamController.play(this.getSelectedSong());
228-
this.mediaPlayer.play(this.getSelectedSong(), true);
229-
}
230-
catch(IOException ioException) {
231-
this.logger.error("Error trying to stream", ioException);
232-
}
233-
}
234-
221+
this.startPlaying(this.getSelectedSong());
235222
}
236223
}
237224

@@ -257,14 +244,6 @@ public void onButtonSkipNextClicked(){
257244
}
258245
}
259246

260-
/**
261-
* This method is called, when a client is renamed, using the ListView.
262-
*/
263-
@FXML
264-
public void onListViewClientEditCommit() {
265-
System.out.println("Client edit commit");
266-
}
267-
268247
/**
269248
* This method gets called, when the isPlaying property of the mediaPlayer changes.
270249
* It handles the play/pause button behavior.
@@ -279,6 +258,28 @@ public void onIsPlayingChanged() {
279258
this.buttonPlayPause.setSelected(false);
280259
}
281260
}
261+
262+
/**
263+
* Starts playing the song.
264+
* Unites the Table-Double-Click function and the play button.
265+
* @param song The song that should start playing.
266+
*/
267+
private void startPlaying(Song song) {
268+
269+
this.logger.info("Trying to play: " + song);
270+
271+
if(this.getSelectedSong() != null) {
272+
// Start streaming...
273+
this.logger.info("Streaming the new song: " + song.getTitle());
274+
try {
275+
this.musicStreamController.play(song);
276+
this.mediaPlayer.play(song, true);
277+
}
278+
catch(IOException ioException) {
279+
this.logger.error("Error trying to stream", ioException);
280+
}
281+
}
282+
}
282283
//endregion
283284

284285
//region initialization
@@ -300,11 +301,11 @@ private void initializeTable() {
300301
this.tableViewSongs.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
301302

302303
tableColumnTitle.setCellValueFactory(
303-
new PropertyValueFactory<Song, String>("title")
304+
new PropertyValueFactory<>("title")
304305
);
305306

306307
tableColumnArtist.setCellValueFactory(
307-
new PropertyValueFactory<Song, String>("artist")
308+
new PropertyValueFactory<>("artist")
308309
);
309310

310311
// Implement DoubleClick for rows.
@@ -314,7 +315,7 @@ private void initializeTable() {
314315
if (event.getClickCount() >= 2 && (!row.isEmpty())) {
315316
// Check if its a song.
316317
if (Song.class.isInstance(row.getItem()))
317-
this.mediaPlayer.play(row.getItem());
318+
this.startPlaying(row.getItem());
318319
}
319320
});
320321
return row;

Server/src/main/resources/views/MainWindow.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</Label>
6666
</children>
6767
</HBox>
68-
<ListView fx:id="listViewClients" editable="true" onEditCommit="#onListViewClientEditCommit" style="-fx-border-color: BBB;" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS" />
68+
<ListView fx:id="listViewClients" style="-fx-border-color: BBB;" GridPane.rowIndex="1" GridPane.vgrow="ALWAYS" />
6969
</children>
7070
<opaqueInsets>
7171
<Insets />

0 commit comments

Comments
 (0)