bugfixing in mpd
This commit is contained in:
parent
e416d44400
commit
0765e1c017
|
@ -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,12 +46,12 @@ public class MPDController implements IMPDController {
|
|||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (mpd) {
|
||||
addToPlayListIfNeeded(artist, title);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) { }
|
||||
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
|
||||
MPDPlaylist playlist = mpd.getMPDPlaylist();
|
||||
|
||||
for(MPDSong song: playlist.getSongList()) {
|
||||
|
@ -63,6 +62,7 @@ public class MPDController implements IMPDController {
|
|||
|
||||
MPDPlayer player = mpd.getMPDPlayer();
|
||||
player.stop();
|
||||
|
||||
player.playId(song);
|
||||
break;
|
||||
}
|
||||
|
@ -73,15 +73,16 @@ public class MPDController implements IMPDController {
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a song to current mpd playlist
|
||||
|
@ -94,7 +95,7 @@ public class MPDController implements IMPDController {
|
|||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
synchronized (mpd) {
|
||||
MPDDatabase db = mpd.getMPDDatabase();
|
||||
MPDPlaylist playlist = mpd.getMPDPlaylist();
|
||||
|
||||
|
@ -115,13 +116,12 @@ public class MPDController implements IMPDController {
|
|||
Logger.sLog("MPD error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
synchronized (lockObject) {
|
||||
new Thread(r).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipRandomStart() {
|
||||
|
@ -129,29 +129,32 @@ public class MPDController implements IMPDController {
|
|||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (mpd) {
|
||||
MPDPlayer player = mpd.getMPDPlayer();
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
|
||||
int length;
|
||||
MPDSong song = player.getCurrentSong();
|
||||
if(song!= null) {
|
||||
length = song.getLength();
|
||||
int skip = new Random().nextInt(length/2);
|
||||
int skip = new Random().nextInt(length/2)+10;
|
||||
player.seek(skip);
|
||||
}
|
||||
} catch (MPDConnectionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (MPDPlayerException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
synchronized (lockObject) {
|
||||
new Thread(r).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current mpd volume
|
||||
|
@ -163,7 +166,7 @@ public class MPDController implements IMPDController {
|
|||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
synchronized (mpd) {
|
||||
try {
|
||||
mpd.getMPDPlayer().setVolume(volume);
|
||||
} catch (MPDConnectionException e) {
|
||||
|
@ -172,13 +175,12 @@ public class MPDController implements IMPDController {
|
|||
Logger.sLog("MPD error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
synchronized (lockObject) {
|
||||
new Thread(r).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current mpd playlist
|
||||
|
@ -189,6 +191,7 @@ public class MPDController implements IMPDController {
|
|||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (mpd) {
|
||||
try {
|
||||
MPDPlaylist playlist = mpd.getMPDPlaylist();
|
||||
playlist.clearPlaylist();
|
||||
|
@ -202,13 +205,12 @@ public class MPDController implements IMPDController {
|
|||
Logger.sLog("MPD error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
synchronized (lockObject) {
|
||||
new Thread(r).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addToPlayListIfNeeded(final String artist, final String title) {
|
||||
MPDDatabase db = mpd.getMPDDatabase();
|
||||
|
|
Loading…
Reference in New Issue