bugfixing in mpd

This commit is contained in:
Lucas Pleß 2012-06-22 01:32:01 +02:00
parent e416d44400
commit 0765e1c017
1 changed files with 84 additions and 82 deletions

View File

@ -21,7 +21,6 @@ import java.util.Random;
*/
public class MPDController implements IMPDController {
private MPD mpd;
private final Object lockObject = new Object();
public MPDController(String host) {
try {
@ -47,39 +46,41 @@ public class MPDController implements IMPDController {
Runnable r = new Runnable() {
@Override
public void run() {
addToPlayListIfNeeded(artist, title);
try {
Thread.sleep(500);
} catch (InterruptedException e) { }
synchronized (mpd) {
addToPlayListIfNeeded(artist, title);
try {
MPDPlaylist playlist = mpd.getMPDPlaylist();
try {
Thread.sleep(200);
for(MPDSong song: playlist.getSongList()) {
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());
} catch (MPDConnectionException e) {
Logger.sLog("MPD error: " + e.getMessage());
} catch (MPDPlayerException e) {
Logger.sLog("MPD error: " + e.getMessage());
} catch (InterruptedException e) {
Logger.sLog("MPD error: " + e.getMessage());
}
}
}
};
}
};
synchronized (lockObject) {
new Thread(r).start();
}
new Thread(r).start();
}
}
@ -94,32 +95,31 @@ public class MPDController implements IMPDController {
Runnable r = new Runnable() {
@Override
public void run() {
synchronized (mpd) {
MPDDatabase db = mpd.getMPDDatabase();
MPDPlaylist playlist = mpd.getMPDPlaylist();
MPDDatabase db = mpd.getMPDDatabase();
MPDPlaylist playlist = mpd.getMPDPlaylist();
try {
List<MPDSong> tracks = new ArrayList<MPDSong>(db.findArtist(artist));
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;
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());
}
} 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());
}
}
};
synchronized (lockObject) {
new Thread(r).start();
}
new Thread(r).start();
}
}
@ -129,27 +129,30 @@ public class MPDController implements IMPDController {
Runnable r = new Runnable() {
@Override
public void run() {
MPDPlayer player = mpd.getMPDPlayer();
synchronized (mpd) {
MPDPlayer player = mpd.getMPDPlayer();
try {
int length;
MPDSong song = player.getCurrentSong();
if(song!= null) {
length = song.getLength();
int skip = new Random().nextInt(length/2);
player.seek(skip);
try {
Thread.sleep(500);
int length;
MPDSong song = player.getCurrentSong();
if(song!= null) {
length = song.getLength();
int skip = new Random().nextInt(length/2)+10;
player.seek(skip);
}
} catch (MPDConnectionException e) {
e.printStackTrace();
} catch (MPDPlayerException e) {
e.printStackTrace();
} catch (InterruptedException ignored) {
}
} catch (MPDConnectionException e) {
e.printStackTrace();
} catch (MPDPlayerException e) {
e.printStackTrace();
}
}
};
synchronized (lockObject) {
new Thread(r).start();
}
new Thread(r).start();
}
}
@ -163,20 +166,19 @@ public class MPDController implements IMPDController {
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 (mpd) {
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();
}
new Thread(r).start();
}
}
@ -189,24 +191,24 @@ public class MPDController implements IMPDController {
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 (mpd) {
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();
}
new Thread(r).start();
}
}