completed mpd connection
This commit is contained in:
parent
076ae82639
commit
1c28a2a381
|
@ -9,12 +9,20 @@ public class TestClass {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) throws InterruptedException {
|
||||||
|
|
||||||
IMPDController mpdController = new MPDController();
|
IMPDController mpdController = new MPDController();
|
||||||
|
|
||||||
|
mpdController.playSong("VNV Nation", "Nemesis");
|
||||||
|
|
||||||
|
Thread.sleep(2000);
|
||||||
|
|
||||||
|
mpdController.playSong("Enter Shikari", "Sorry, You're Not A Winner");
|
||||||
|
|
||||||
|
|
||||||
|
Thread.sleep(2000);
|
||||||
|
mpdController.playSong("Calabria", "Pump It Up (Club Mix)");
|
||||||
|
|
||||||
mpdController.playSong("VNV Nation", "Perpetual");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,15 @@ package de.ctdo.crashtest.game;
|
||||||
import de.ctdo.crashtest.domotics.*;
|
import de.ctdo.crashtest.domotics.*;
|
||||||
import de.ctdo.crashtest.gui.*;
|
import de.ctdo.crashtest.gui.*;
|
||||||
import de.ctdo.crashtest.irc.*;
|
import de.ctdo.crashtest.irc.*;
|
||||||
|
import de.ctdo.crashtest.mpd.IMPDController;
|
||||||
|
import de.ctdo.crashtest.mpd.MPDController;
|
||||||
|
|
||||||
public class TheGame implements StateChangeListener, GuiEventListener, IRCEventListener {
|
public class TheGame implements StateChangeListener, GuiEventListener, IRCEventListener {
|
||||||
private IGuiControl guiControl;
|
private IGuiControl guiControl;
|
||||||
private IIrcClient ircClient;
|
private IIrcClient ircClient;
|
||||||
private IStatemachine machine;
|
private IStatemachine machine;
|
||||||
private IBuntiClient bunti;
|
private IBuntiClient bunti;
|
||||||
|
private IMPDController mpdController;
|
||||||
|
|
||||||
private int timertSeconds = 0;
|
private int timertSeconds = 0;
|
||||||
private int timertSecondsLast = 0;
|
private int timertSecondsLast = 0;
|
||||||
|
@ -23,6 +26,7 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
|
||||||
this.ircClient = new IrcClient();
|
this.ircClient = new IrcClient();
|
||||||
this.machine = new Statemachine();
|
this.machine = new Statemachine();
|
||||||
this.bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
this.bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
||||||
|
this.mpdController = new MPDController();
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
@ -47,11 +51,13 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
|
||||||
|
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case IDLE:
|
case IDLE:
|
||||||
|
mpdController.playSong("VNV Nation", "Nemesis");
|
||||||
bunti.setPar56(0,0,0);
|
bunti.setPar56(0,0,0);
|
||||||
bunti.setLampel(false,false,false);
|
bunti.setLampel(false,false,false);
|
||||||
guiControl.showCountDown(false);
|
guiControl.showCountDown(false);
|
||||||
break;
|
break;
|
||||||
case ENTERED_ROOM:
|
case ENTERED_ROOM:
|
||||||
|
mpdController.playSong("Blümchen", "Herz an Herz");
|
||||||
bunti.setLampel(false,false,false);
|
bunti.setLampel(false,false,false);
|
||||||
bunti.setPar56(20,0,100);
|
bunti.setPar56(20,0,100);
|
||||||
break;
|
break;
|
||||||
|
@ -83,6 +89,9 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
|
||||||
case TABLE_GAME_SEVEN:
|
case TABLE_GAME_SEVEN:
|
||||||
bunti.setLampel(false,false,true);
|
bunti.setLampel(false,false,true);
|
||||||
bunti.setPar56(255,100,0);
|
bunti.setPar56(255,100,0);
|
||||||
|
mpdController.playSong("K2", "Der berg ruft");
|
||||||
|
ircClient.say("table game complete");
|
||||||
|
sayScore();
|
||||||
break;
|
break;
|
||||||
case TABLE_FINISH: // und roket muss starten
|
case TABLE_FINISH: // und roket muss starten
|
||||||
bunti.setLampel(false,false,true);
|
bunti.setLampel(false,false,true);
|
||||||
|
@ -132,7 +141,7 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
|
||||||
} else if(message.startsWith("timer")) {
|
} else if(message.startsWith("timer")) {
|
||||||
handleTimerCommand(message);
|
handleTimerCommand(message);
|
||||||
} else if(message.startsWith("score")) {
|
} else if(message.startsWith("score")) {
|
||||||
handleScoreCommand(message);
|
sayScore();
|
||||||
} else if(message.startsWith("wall")) {
|
} else if(message.startsWith("wall")) {
|
||||||
guiControl.setWall(message.substring("wall".length()).trim());
|
guiControl.setWall(message.substring("wall".length()).trim());
|
||||||
} else if(message.startsWith("extra")) {
|
} else if(message.startsWith("extra")) {
|
||||||
|
@ -199,7 +208,7 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleScoreCommand(final String message) {
|
private void sayScore() {
|
||||||
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
|
ircClient.say("stateChangeCounter: " + machine.getStateChangeCounter());
|
||||||
ircClient.say("timerlast: " + timertSecondsLast / 10);
|
ircClient.say("timerlast: " + timertSecondsLast / 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventListener, ILogger {
|
public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventListener, ILogger {
|
||||||
private final List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
|
private final List<IRCEventListener> listenerListIRC = new ArrayList<IRCEventListener>();
|
||||||
private final static String CHANNEL = "#crashtest2";
|
private final static String CHANNEL = "#crashtest";
|
||||||
private Session ircsession;
|
private Session ircsession;
|
||||||
|
|
||||||
public IrcClient() {
|
public IrcClient() {
|
||||||
|
|
|
@ -21,11 +21,15 @@ public class Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String message) {
|
public void log(String message) {
|
||||||
|
|
||||||
System.out.println("LOG: " + message);
|
System.out.println("LOG: " + message);
|
||||||
|
|
||||||
for(ILogger logger: loggerList) {
|
for(ILogger logger: loggerList) {
|
||||||
logger.log(message);
|
synchronized (this) {
|
||||||
|
logger.log(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sLog(String message) {
|
public static void sLog(String message) {
|
||||||
|
|
|
@ -5,6 +5,6 @@ package de.ctdo.crashtest.mpd;
|
||||||
* @date: 01.06.12 10:36
|
* @date: 01.06.12 10:36
|
||||||
*/
|
*/
|
||||||
public interface IMPDController {
|
public interface IMPDController {
|
||||||
void playSong(String artist, String title);
|
void playSong(final String artist, final String title);
|
||||||
void setVolume(int volume);
|
void setVolume(final int volume);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
package de.ctdo.crashtest.mpd;
|
package de.ctdo.crashtest.mpd;
|
||||||
|
|
||||||
|
import de.ctdo.crashtest.game.TheGame;
|
||||||
import de.ctdo.crashtest.log.Logger;
|
import de.ctdo.crashtest.log.Logger;
|
||||||
import org.bff.javampd.MPD;
|
import org.bff.javampd.MPD;
|
||||||
import org.bff.javampd.MPDDatabase;
|
import org.bff.javampd.MPDDatabase;
|
||||||
import org.bff.javampd.MPDPlayer;
|
import org.bff.javampd.MPDPlayer;
|
||||||
|
import org.bff.javampd.MPDPlaylist;
|
||||||
import org.bff.javampd.exception.MPDConnectionException;
|
import org.bff.javampd.exception.MPDConnectionException;
|
||||||
import org.bff.javampd.exception.MPDDatabaseException;
|
import org.bff.javampd.exception.MPDDatabaseException;
|
||||||
|
import org.bff.javampd.exception.MPDPlayerException;
|
||||||
|
import org.bff.javampd.exception.MPDPlaylistException;
|
||||||
import org.bff.javampd.objects.MPDSong;
|
import org.bff.javampd.objects.MPDSong;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: lucas
|
* @author: lucas
|
||||||
|
@ -18,7 +24,6 @@ import java.util.Collection;
|
||||||
public class MPDController implements IMPDController {
|
public class MPDController implements IMPDController {
|
||||||
|
|
||||||
private MPD mpd;
|
private MPD mpd;
|
||||||
private MPDPlayer player;
|
|
||||||
|
|
||||||
public MPDController() {
|
public MPDController() {
|
||||||
initMPD();
|
initMPD();
|
||||||
|
@ -28,36 +33,100 @@ public class MPDController implements IMPDController {
|
||||||
private void initMPD() {
|
private void initMPD() {
|
||||||
try {
|
try {
|
||||||
mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600);
|
mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600);
|
||||||
player = mpd.getMPDPlayer();
|
|
||||||
|
|
||||||
MPDDatabase database = mpd.getMPDDatabase();
|
|
||||||
|
|
||||||
Collection<MPDSong> bla = database.findTitle("");
|
|
||||||
|
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
Logger.sLog("MPD error: " + e.getMessage());
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
|
} catch (MPDConnectionException e) {
|
||||||
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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();
|
||||||
|
|
||||||
|
for(MPDSong song: playlist.getSongList()) {
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Thread(r).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToPlayListIfNeeded(final String artist, final String title) {
|
||||||
|
MPDDatabase db = mpd.getMPDDatabase();
|
||||||
|
MPDPlaylist playlist = mpd.getMPDPlaylist();
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<MPDSong> tracks = new ArrayList<MPDSong>(db.findArtist(artist));
|
||||||
|
|
||||||
|
for(MPDSong song: tracks) {
|
||||||
|
if(song.getName() != null &&
|
||||||
|
song.getName().toLowerCase().contains(title.toLowerCase())) {
|
||||||
|
|
||||||
|
if(!playlist.getSongList().contains(song)) {
|
||||||
|
playlist.addSong(song);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (MPDConnectionException e) {
|
} catch (MPDConnectionException e) {
|
||||||
Logger.sLog("MPD error: " + e.getMessage());
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
} catch (MPDDatabaseException e) {
|
} catch (MPDDatabaseException e) {
|
||||||
Logger.sLog("MPD error: " + e.getMessage());
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
|
} catch (MPDPlaylistException e) {
|
||||||
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playSong(String artist, String title) {
|
public void setVolume(final int volume) {
|
||||||
if(mpd != null && player != null) {
|
if(mpd != null) {
|
||||||
|
|
||||||
// MPDSong finden in der DB
|
Runnable r = new Runnable() {
|
||||||
// dann abspielen
|
@Override
|
||||||
|
public void run() {
|
||||||
}
|
try {
|
||||||
}
|
mpd.getMPDPlayer().setVolume(volume);
|
||||||
|
} catch (MPDConnectionException e) {
|
||||||
@Override
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
public void setVolume(int volume) {
|
} catch (MPDPlayerException e) {
|
||||||
if(mpd != null && player != null) {
|
Logger.sLog("MPD error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Thread(r).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue