@@ -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 ;
0 commit comments