removed threads from mpdcontroller

This commit is contained in:
Lucas Pleß 2012-06-15 09:33:15 +02:00
parent 28989f2511
commit da3aef9704
1 changed files with 49 additions and 82 deletions

View File

@ -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<MPDSong> tracks = new ArrayList<MPDSong>(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<MPDSong> tracks = new ArrayList<MPDSong>(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());
}
}
}