Commit 5f52d736 authored by Nico Mack's avatar Nico Mack

Added volume control to MediaDelegate

Added Interactions to StatefulWidget
parent 474e1ec2
......@@ -29,12 +29,16 @@ import java.net.URL;
import java.util.Map;
import javax.media.Controller;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Format;
import javax.media.GainControl;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PlugInManager;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.media.format.AudioFormat;
......@@ -48,7 +52,7 @@ import javax.media.format.AudioFormat;
// * Class Definition and Members *
// ***************************************************************************
public class AudioDelegate extends MediaDelegate implements Playable {
public class AudioDelegate extends MediaDelegate implements Playable, ControllerListener {
private Player player;
private Map<String, Method> doableMethods;
......@@ -103,6 +107,8 @@ public class AudioDelegate extends MediaDelegate implements Playable {
MediaLocator locator = new MediaLocator(mediaUrl);
this.player = Manager.createPlayer(locator);
this.player.realize();
this.player.addControllerListener(this);
this.player.prefetch();
} catch (NoPlayerException | IOException e) {
LOGGER.error("Failed to prepare media {} in {}!", this.media, this.baseUrl, e); //$NON-NLS-1$
......@@ -175,6 +181,18 @@ public class AudioDelegate extends MediaDelegate implements Playable {
}
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public void controllerUpdate(ControllerEvent event) {
if (event instanceof RealizeCompleteEvent) {
GainControl gain = this.player.getGainControl();
gain.setDB(this.volume);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
......
......@@ -34,6 +34,15 @@ public abstract class MediaDelegate extends Delegate {
protected URL baseUrl;
protected String media;
protected String mimeTpye;
protected int volume;
// ***************************************************************************
// * Constants *
// ***************************************************************************
public static final int MIN_VOLUME = -40;
public static final int DEFAULT_VOLUME = 0; // db
public static final int MAX_VOLUME = 6;
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -51,6 +60,7 @@ public abstract class MediaDelegate extends Delegate {
this.baseUrl = builder.baseUrl;
this.media = builder.media;
this.mimeTpye = builder.mimeType;
this.volume = builder.volume;
}
// ---------------------------------------------------------------------------
......
......@@ -49,6 +49,7 @@ public abstract class BaseMediaDelegateBuilder<B extends BaseMediaDelegateBuilde
public URL baseUrl;
public String media;
public String mimeType;
public int volume;
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -108,6 +109,10 @@ public abstract class BaseMediaDelegateBuilder<B extends BaseMediaDelegateBuilde
media = BootstrappingUtils.getContentAsString(rootElement, Externalization.MEDIA_NODE, BootstrappingUtils.MANDATORY, null, context);
mimeType = BootstrappingUtils.getContentAsString(rootElement, Externalization.MIME_TYPE_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING, context);
volume = BootstrappingUtils.getContentAsInteger(rootElement, Externalization.VOLUME_NODE, BootstrappingUtils.OPTIONAL, MediaDelegate.DEFAULT_VOLUME, context);
volume = Math.min(volume, MediaDelegate.MAX_VOLUME);
volume = Math.max(volume, MediaDelegate.MIN_VOLUME);
}
// ---------------------------------------------------------------------------
......
......@@ -22,6 +22,7 @@ package lu.list.itis.dkd.tui.widget;
import lu.list.itis.dkd.dbc.annotation.NonNullByDefault;
import lu.list.itis.dkd.tui.adapter.TangibleObject;
import lu.list.itis.dkd.tui.event.interaction.Interaction;
import lu.list.itis.dkd.tui.logging.TangibleLogger;
import lu.list.itis.dkd.tui.utility.Point;
import lu.list.itis.dkd.tui.widget.builder.BaseStatefulBuilder;
......@@ -162,11 +163,21 @@ public class StatefulWidget extends BaseWidget {
if (wasStill) {
if (manager.isMoving()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.TRANSLATED);
this.respondTo(Interaction.ON_TRANSLATE_BEGIN);
} else if (manager.isRotating()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.ROTATED);
this.respondTo(Interaction.ON_ROTATE_BEGIN);
}
} else if (wasMoving && manager.isStill()) {
TangibleLogger.logWidget(tangibleObject.getObjectId(), manager.getLastPosition(), TangibleLogger.STOPPED);
if (manager.wasMoving()) {
this.respondTo(Interaction.ON_TRANSLATE_END);
}
if (manager.wasRotating()) {
this.respondTo(Interaction.ON_ROTATE_END);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment