@@ -0,0 +1,2253 @@
+package com.gabrielavara.musicplayer.controllers;%0A%0Aimport com.gabrielavara.musicplayer.api.service.Mp3;%0Aimport javafx.beans.value.ChangeListener;%0Aimport javafx.beans.value.ObservableValue;%0Aimport javafx.scene.media.Media;%0Aimport javafx.scene.media.MediaPlayer;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.UnsupportedEncodingException;%0Aimport java.net.URLEncoder;%0Aimport java.nio.file.Paths;%0A%0Apublic class PlaylistSelectionChangedListener implements ChangeListener%3CMp3%3E %7B%0A    private static Logger log = LoggerFactory.getLogger(%22com.gabrielavara.musicplayer.controllers.PlaylistSelectionChangedListener%22);%0A    private PlayerController playerController;%0A%0A    PlaylistSelectionChangedListener(PlayerController playerController) %7B%0A        this.playerController = playerController;%0A    %7D%0A%0A    @Override%0A    public void changed(ObservableValue%3C? extends Mp3%3E observable, Mp3 oldValue, Mp3 newValue) %7B%0A        log.info(%22Playlist selection changed from: %7B%7D, to %7B%7D%22, oldValue, newValue);%0A        newValue.setCurrentlyPlaying(true);%0A        playerController.getArtist().setText(newValue.getArtist());%0A        playerController.getTitle().setText(newValue.getTitle());%0A        play(newValue);%0A        if (oldValue != null) %7B%0A            oldValue.setCurrentlyPlaying(false);%0A        %7D%0A    %7D%0A%0A    private void play(Mp3 newValue) %7B%0A        MediaPlayer mediaPlayer = playerController.getMediaPlayer();%0A        if (mediaPlayer != null) %7B%0A            mediaPlayer.stop();%0A        %7D%0A        String mediaUrl = createMediaUrl(newValue);%0A        if (mediaUrl != null) %7B%0A            Media media = new Media(mediaUrl);%0A            playerController.setMediaPlayer(new MediaPlayer(media));%0A            mediaPlayer = playerController.getMediaPlayer();%0A            mediaPlayer.play();%0A        %7D%0A    %7D%0A%0A    private String createMediaUrl(Mp3 newValue) %7B%0A        try %7B%0A            String path = Paths.get(newValue.getFilename()).toAbsolutePath().toString();%0A            String mediaUrl = URLEncoder.encode(path, %22UTF-8%22);%0A            return %22file:/%22 + mediaUrl.replace(%22%5C%5C%22, %22/%22).replace(%22+%22, %22%2520%22);%0A        %7D catch (UnsupportedEncodingException e) %7B%0A            log.error(%22Could not play mp3: %7B%7D%22, e.getMessage());%0A        %7D%0A        return null;%0A    %7D%0A%7D%0A

add PlaylistSelectionChangedListener