Applicaties gecontroleerd: GOM, MPC, VLC

Bugs opgelost: Extreme3D WiiMote
Mooier favicon toegevoegd.
This commit is contained in:
Bram Veenboer
2011-06-11 16:46:46 +00:00
parent ea73819797
commit e0b8456bcb
12 changed files with 208 additions and 44 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Map;
import javax.swing.JToggleButton;
import mimis.application.cmd.windows.winamp.WinampApplication;
import mimis.exception.worker.DeactivateException;
import mimis.manager.Exitable;
import mimis.manager.ManageButton;
@@ -30,7 +31,9 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
public void stop() throws DeactivateException {
super.stop();
for (T manageable : manageableArray) {
manageable.stop();
if (!(manageable instanceof WinampApplication)) {
manageable.stop();
}
}
}

View File

@@ -22,10 +22,14 @@ public abstract class CMDApplication extends Application {
this.title = title;
}
public String getPath() {
String key = String.format("%s\\%s", REGISTRY, program);
return Native.getValue(key);
}
public void activate() throws ActivateException {
super.activate();
String key = String.format("%s\\%s", REGISTRY, program);
String path = Native.getValue(key);
String path = getPath();
if (path == null) {
throw new ActivateException();
}

View File

@@ -23,6 +23,12 @@ public class GomPlayerApplication extends WindowsApplication {
volumeWorker = new VolumeWorker();
seekWorker = new SeekWorker();
}
public void stop() throws DeactivateException {
super.stop();
volumeWorker.stop();
seekWorker.stop();
}
public void begin(Action action) {
log.trace("GomPlayerApplication begin: " + action);

View File

@@ -1,6 +1,9 @@
package mimis.application.mpc;
import mimis.Worker;
import mimis.application.cmd.windows.WindowsApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.value.Action;
public class MPCApplication extends WindowsApplication {
@@ -8,11 +11,41 @@ public class MPCApplication extends WindowsApplication {
protected final static String TITLE = "Media Player Classic";
protected final static String NAME = "MediaPlayerClassicW";
protected static final int VOLUME_SLEEP = 50;
protected static final int SEEK_SLEEP = 50;
protected VolumeWorker volumeWorker;
protected SeekWorker seekWorker;
public MPCApplication() {
super(PROGRAM, TITLE, NAME);
volumeWorker = new VolumeWorker();
seekWorker = new SeekWorker();
}
public void action(Action action) {
public void begin(Action action) {
log.trace("MPCApplication: " + action);
try {
switch (action) {
case FORWARD:
seekWorker.activate(1);
break;
case REWIND:
seekWorker.activate(-1);
break;
case VOLUME_UP:
volumeWorker.activate(1);
break;
case VOLUME_DOWN:
volumeWorker.activate(-1);
break;
}
} catch (ActivateException e) {
log.error(e);
}
}
public void end(Action action) {
log.trace("MPCApplication: " + action);
switch (action) {
case PLAY:
@@ -25,19 +58,23 @@ public class MPCApplication extends WindowsApplication {
command(920);
break;
case FORWARD:
command(900);
break;
case REWIND:
command(889);
try {
seekWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case MUTE:
command(909);
break;
case VOLUME_UP:
command(907);
break;
case VOLUME_DOWN:
command(908);
try {
volumeWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case FULLSCREEN:
command(830);
@@ -49,4 +86,31 @@ public class MPCApplication extends WindowsApplication {
return TITLE;
}
protected class VolumeWorker extends Worker {
protected int volumeChangeSign;
public void activate(int volumeChangeSign) throws ActivateException {
super.activate();
this.volumeChangeSign = volumeChangeSign;
}
public void work() {
command(volumeChangeSign > 0 ? 907 : 908);
sleep(VOLUME_SLEEP);
}
};
protected class SeekWorker extends Worker {
protected int seekDirection;
public void activate(int seekDirection) throws ActivateException {
super.activate();
this.seekDirection = seekDirection;
}
public void work() {
command(seekDirection > 0 ? 900 : 889);
sleep(SEEK_SLEEP);
}
};
}

View File

@@ -4,37 +4,56 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mimis.Worker;
import mimis.application.cmd.CMDApplication;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.util.Native;
import mimis.value.Action;
import mimis.value.Amount;
public class VLCApplication extends CMDApplication {
protected final static String REGISTRY = "HKEY_CLASSES_ROOT\\Applications\\vlc.exe\\shell\\Open\\command";
protected final static String PROGRAM = "vlc.exe";
protected final static String TITLE = "VLC media player";
protected static final int POSTION_CHANGE_RATE = 1;
protected static final int VOLUME_CHANGE_RATE = 20;
protected static final String HOST = "127.0.0.1"; // localhost
protected static final int PORT = 1234;
protected static final String HOST = "localhost";
protected static final int PORT = 8080;
protected static final int VOLUME_SLEEP = 100;
protected static final int SEEK_SLEEP = 100;
protected VolumeWorker volumeWorker;
protected SeekWorker seekWorker;
protected int volume = 255;
protected boolean muted = false;
public VLCApplication() {
super(PROGRAM, TITLE);
volumeWorker = new VolumeWorker();
seekWorker = new SeekWorker();
}
public String getPath() {
Pattern pattern = Pattern.compile("\"([^\"]+)\"");
Matcher matcher = pattern.matcher(Native.getValue(REGISTRY));
return matcher.find() ? matcher.group(1) : null;
}
public void command(String command) {
//String request = "http://" + HOST + ":" + PORT + "/requests/status.xml?command=" + command;
String request = String.format("http://%s:%d/requests/status.xml?command=%s", HOST, PORT, command);
try {
// Todo: check response voor 200, status ok
//int response = ((HttpURLConnection)(new URL(request)).openConnection()).getResponseCode();
URL url = new URL(request);
HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
int response = httpUrlConnection.getResponseCode();
log.debug("Response: " + response);
log.trace("Response: " + response);
} catch (MalformedURLException e) {
log.error(e);
} catch (IOException e) {
@@ -42,6 +61,34 @@ public class VLCApplication extends CMDApplication {
}
}
public void stop() throws DeactivateException {
super.stop();
volumeWorker.stop();
seekWorker.stop();
}
public void begin(Action action) {
log.trace("VLCApplication begin: " + action);
try {
switch (action) {
case VOLUME_UP:
volumeWorker.activate("+");
break;
case VOLUME_DOWN:
volumeWorker.activate("-");
break;
case FORWARD:
seekWorker.activate(Amount.SMALL, "+");
break;
case REWIND:
seekWorker.activate(Amount.SMALL, "-");
break;
}
} catch (ActivateException e) {
log.error(e);
}
}
public void end(Action action) {
log.trace("VLCApplication end: " + action);
switch (action) {
@@ -58,19 +105,23 @@ public class VLCApplication extends CMDApplication {
command("pl_previous");
break;
case FORWARD:
command("command=seek&val=+" + POSTION_CHANGE_RATE);
break;
case REWIND:
command("command=seek&val=-" + POSTION_CHANGE_RATE);
try {
seekWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case MUTE:
command("volume&val=" + toggleMute());
break;
case VOLUME_UP:
volumeUp();
break;
case VOLUME_DOWN:
volumeDown();
try {
volumeWorker.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
break;
case SHUFFLE:
command("command=pl_random");
@@ -102,4 +153,45 @@ public class VLCApplication extends CMDApplication {
public String title() {
return TITLE;
}
protected class VolumeWorker extends Worker {
protected String volumeChangeSign;
public void activate(String volumeChangeSign) throws ActivateException {
super.activate();
this.volumeChangeSign = volumeChangeSign;
}
public void work() {
volume += VOLUME_CHANGE_RATE;
command("volume&val=" + volumeChangeSign + VOLUME_CHANGE_RATE);
sleep(VOLUME_SLEEP);
}
};
protected class SeekWorker extends Worker {
protected Amount amount;
protected String seekDirection;
public void activate(Amount amount, String seekDirection) throws ActivateException {
super.activate();
this.amount = amount;
this.seekDirection = seekDirection;
}
public void work() {
switch (amount) {
case SMALL:
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE);
break;
case MEDIUM:
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE * 2);
break;
case LARGE:
command("command=seek&val=" + seekDirection + POSTION_CHANGE_RATE * 3);
break;
}
sleep(SEEK_SLEEP);
}
};
}

View File

@@ -48,9 +48,7 @@ public abstract class JavaInputDevice extends Device {
}
}
public void processEvent(JXInputAxisEvent event) {
//log.trace("JXInputAxisEvent: " + event);
}
public void processEvent(JXInputAxisEvent event) {}
public void processEvent(JXInputButtonEvent event) throws ButtonException {
Button button = getButton(event);

View File

@@ -6,8 +6,6 @@ import java.util.Queue;
import mimis.Worker;
import mimis.exception.ButtonException;
import de.hardcode.jxinput.Axis;
import de.hardcode.jxinput.Button;
import de.hardcode.jxinput.Directional;
import de.hardcode.jxinput.JXInputDevice;
@@ -37,12 +35,12 @@ public class JavaInputListener extends Worker implements Runnable, JXInputAxisEv
}
protected void addListeners() {
for (int i = 0; i < jxinputDevice.getMaxNumberOfAxes(); ++i) {
/*for (int i = 0; i < jxinputDevice.getMaxNumberOfAxes(); ++i) {
Axis axis = jxinputDevice.getAxis(i);
if (axis != null) {
JXInputEventManager.addListener(this, axis);
}
}
}*/
for (int i = 0; i < jxinputDevice.getMaxNumberOfButtons(); ++i) {
Button button = jxinputDevice.getButton(i);
if (button != null) {

View File

@@ -5,18 +5,18 @@ import mimis.exception.button.UnknownButtonException;
import de.hardcode.jxinput.event.JXInputButtonEvent;
public enum Extreme3DButton implements Button {
ONE ("ManageButton 0"),
TWO ("ManageButton 1"),
THREE ("ManageButton 2"),
FOUR ("ManageButton 3"),
FIVE ("ManageButton 4"),
SIX ("ManageButton 5"),
SEVEN ("ManageButton 6"),
EIGHT ("ManageButton 7"),
NINE ("ManageButton 8"),
TEN ("ManageButton 9"),
ELEVEN ("ManageButton 10"),
TWELVE ("ManageButton 11");
ONE ("Button 0"),
TWO ("Button 1"),
THREE ("Button 2"),
FOUR ("Button 3"),
FIVE ("Button 4"),
SIX ("Button 5"),
SEVEN ("Button 6"),
EIGHT ("Button 7"),
NINE ("Button 8"),
TEN ("Button 9"),
ELEVEN ("Button 10"),
TWELVE ("Button 11");
protected String code;

View File

@@ -48,9 +48,9 @@ public class WiimoteDevice extends Device implements GestureListener {
/* Worker */
public void activate() throws ActivateException {
super.activate();
connect();
add(eventMapCycle.player);
super.activate();
}
public boolean active() {
@@ -133,7 +133,7 @@ public class WiimoteDevice extends Device implements GestureListener {
}
public void feedback(Feedback feedback) {
if (active()) {
if (wiimote != null && active()) {
log.debug("Wiimote rumble feedback");
wiimote.rumble(RUMBLE);
}