fixed mpd nullpointer exceptions

This commit is contained in:
Lucas Pleß 2012-06-28 20:12:36 +02:00
parent f106675753
commit 8acace8c19
1 changed files with 12 additions and 6 deletions

View File

@ -48,7 +48,7 @@ public class MPDController implements IMPDController {
@Override @Override
public void run() { public void run() {
synchronized (mpd) { synchronized (mpd) {
addToPlayListIfNeeded(artist, title);
doPlaySong(artist,title); doPlaySong(artist,title);
} }
@ -68,6 +68,8 @@ public class MPDController implements IMPDController {
int tries = 3; int tries = 3;
while(tries>0) { while(tries>0) {
addToPlayListIfNeeded(artist, title);
for(MPDSong song: playlist.getSongList()) { for(MPDSong song: playlist.getSongList()) {
if(checkSong(song, artist, title)) { if(checkSong(song, artist, title)) {
System.out.println("MPD: stopping, playing, go..."); System.out.println("MPD: stopping, playing, go...");
@ -85,7 +87,7 @@ public class MPDController implements IMPDController {
System.out.println("MPD: song is correctly playing"); System.out.println("MPD: song is correctly playing");
return; return;
} else { } else {
System.out.println("MPD: wrong track is playing. " + song.getArtist() + " - " + song.getTitle()); System.out.println("MPD: wrong track is playing");
} }
System.out.println("MPD: next try"); System.out.println("MPD: next try");
@ -102,11 +104,15 @@ public class MPDController implements IMPDController {
} }
private boolean checkSong(final MPDSong song, final String artist, final String title) { private boolean checkSong(final MPDSong song, final String artist, final String title) {
if(song != null) {
if(song.getArtist() != null && song.getTitle() != null) { if(song.getArtist() != null && song.getTitle() != null) {
if(song.getArtist().getName().toLowerCase().contentEquals(artist.toLowerCase()) && if(song.getArtist().getName().toLowerCase().contentEquals(artist.toLowerCase()) &&
song.getTitle().toLowerCase().contentEquals(title.toLowerCase())) { song.getTitle().toLowerCase().contentEquals(title.toLowerCase())) {
return true; return true;
} }
} else {
System.out.println("MPD: song is nullb");
}
} else { } else {
System.out.println("MPD: track title or artist is null " + artist + " - " + title); System.out.println("MPD: track title or artist is null " + artist + " - " + title);
} }