From da3aef97046b3df33863d5be37f82fd478ff5f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Fri, 15 Jun 2012 09:33:15 +0200 Subject: [PATCH] removed threads from mpdcontroller --- src/de/ctdo/crashtest/mpd/MPDController.java | 131 +++++++------------ 1 file changed, 49 insertions(+), 82 deletions(-) diff --git a/src/de/ctdo/crashtest/mpd/MPDController.java b/src/de/ctdo/crashtest/mpd/MPDController.java index 2ee7446..0d4a11c 100644 --- a/src/de/ctdo/crashtest/mpd/MPDController.java +++ b/src/de/ctdo/crashtest/mpd/MPDController.java @@ -41,39 +41,32 @@ public class MPDController implements IMPDController { @Override public void playSong(final String artist, final String title) { if(mpd != null) { - Runnable r = new Runnable() { - @Override - public void run() { - addToPlayListIfNeeded(artist, title); - try { - MPDPlaylist playlist = mpd.getMPDPlaylist(); + addToPlayListIfNeeded(artist, title); - for(MPDSong song: playlist.getSongList()) { + try { + MPDPlaylist playlist = mpd.getMPDPlaylist(); - if(song.getArtist() != null && song.getTitle() != null) { - if(song.getArtist().getName().toLowerCase().equals(artist.toLowerCase()) && - song.getTitle().toLowerCase().equals(title.toLowerCase())) { + for(MPDSong song: playlist.getSongList()) { - MPDPlayer player = mpd.getMPDPlayer(); - player.stop(); - player.playId(song); - break; - } - } + if(song.getArtist() != null && song.getTitle() != null) { + if(song.getArtist().getName().toLowerCase().equals(artist.toLowerCase()) && + song.getTitle().toLowerCase().equals(title.toLowerCase())) { + + MPDPlayer player = mpd.getMPDPlayer(); + player.stop(); + player.playId(song); + break; } - - } catch (MPDConnectionException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDPlayerException e) { - Logger.sLog("MPD error: " + e.getMessage()); } } - }; - synchronized (lockObject) { - new Thread(r).start(); + } catch (MPDConnectionException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDPlayerException e) { + Logger.sLog("MPD error: " + e.getMessage()); } + } } @@ -85,33 +78,25 @@ public class MPDController implements IMPDController { @Override public void addToPlayList(final String artist, final String title) { if(mpd != null) { - Runnable r = new Runnable() { - @Override - public void run() { - MPDDatabase db = mpd.getMPDDatabase(); - MPDPlaylist playlist = mpd.getMPDPlaylist(); - try { - List tracks = new ArrayList(db.findArtist(artist)); + MPDDatabase db = mpd.getMPDDatabase(); + MPDPlaylist playlist = mpd.getMPDPlaylist(); - for(MPDSong song: tracks) { - if(song.getName() != null && song.getName().toLowerCase().contains(title.toLowerCase())) { - playlist.addSong(song); - break; - } - } - } catch (MPDConnectionException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDDatabaseException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDPlaylistException e) { - Logger.sLog("MPD error: " + e.getMessage()); + try { + List tracks = new ArrayList(db.findArtist(artist)); + + for(MPDSong song: tracks) { + if(song.getName() != null && song.getName().toLowerCase().contains(title.toLowerCase())) { + playlist.addSong(song); + break; } } - }; - - synchronized (lockObject) { - new Thread(r).start(); + } catch (MPDConnectionException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDDatabaseException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDPlaylistException e) { + Logger.sLog("MPD error: " + e.getMessage()); } } } @@ -123,21 +108,12 @@ public class MPDController implements IMPDController { @Override public void setVolume(final int volume) { if(mpd != null) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - mpd.getMPDPlayer().setVolume(volume); - } catch (MPDConnectionException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDPlayerException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } - } - }; - - synchronized (lockObject) { - new Thread(r).start(); + try { + mpd.getMPDPlayer().setVolume(volume); + } catch (MPDConnectionException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDPlayerException e) { + Logger.sLog("MPD error: " + e.getMessage()); } } } @@ -148,26 +124,17 @@ public class MPDController implements IMPDController { @Override public void clearPlaylist() { if(mpd != null) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - MPDPlaylist playlist = mpd.getMPDPlaylist(); - playlist.clearPlaylist(); - mpd.getMPDPlayer().setRandom(false); - mpd.getMPDPlayer().setXFade(1); - } catch (MPDConnectionException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDPlaylistException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } catch (MPDPlayerException e) { - Logger.sLog("MPD error: " + e.getMessage()); - } - } - }; - - synchronized (lockObject) { - new Thread(r).start(); + try { + MPDPlaylist playlist = mpd.getMPDPlaylist(); + playlist.clearPlaylist(); + mpd.getMPDPlayer().setRandom(false); + mpd.getMPDPlayer().setXFade(1); + } catch (MPDConnectionException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDPlaylistException e) { + Logger.sLog("MPD error: " + e.getMessage()); + } catch (MPDPlayerException e) { + Logger.sLog("MPD error: " + e.getMessage()); } } }