Skip to content

Commit

Permalink
Merge pull request 4thline#106 from ened/workbench-playmode
Browse files Browse the repository at this point in the history
Added a PlayMode panel to the AVTransport controller.
  • Loading branch information
ened committed Mar 27, 2015
2 parents 9c47402 + 27dbc09 commit 6a686e2
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2013 4th Line GmbH, Switzerland
*
* The contents of this file are subject to the terms of either the GNU
* Lesser General Public License Version 2 or later ("LGPL") or the
* Common Development and Distribution License Version 1 or later
* ("CDDL") (collectively, the "License"). You may not use this file
* except in compliance with the License. See LICENSE.txt for more
* information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

package org.fourthline.cling.support.avtransport.callback;

import org.fourthline.cling.controlpoint.ActionCallback;
import org.fourthline.cling.model.action.ActionInvocation;
import org.fourthline.cling.model.meta.Service;
import org.fourthline.cling.model.types.UnsignedIntegerFourBytes;
import org.fourthline.cling.support.model.PlayMode;

import java.util.logging.Logger;

/**
* @author Christian Bauer
*/
public abstract class SetPlayMode extends ActionCallback {

private static Logger log = Logger.getLogger(SetPlayMode.class.getName());

public SetPlayMode(Service service, PlayMode playMode) {
this(new UnsignedIntegerFourBytes(0), service, playMode);
}

public SetPlayMode(UnsignedIntegerFourBytes instanceId, Service service, PlayMode playMode) {
super(new ActionInvocation(service.getAction("SetPlayMode")));
getActionInvocation().setInput("InstanceID", instanceId);
getActionInvocation().setInput("NewPlayMode", playMode.toString());
}

@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.fourthline.cling.workbench.plugins.avtransport;

import org.fourthline.cling.support.model.PlayMode;
import org.fourthline.cling.support.model.PositionInfo;
import org.fourthline.cling.support.model.TransportState;
import org.fourthline.cling.support.shared.View;
Expand Down Expand Up @@ -43,12 +44,16 @@ public interface Presenter {
void onNextSelected(int instanceId);

void onUpdatePositionInfo(int instanceId);

void onSetPlayModeSelected(int instanceId, PlayMode playMode);
}

void init(int instanceId);

void setState(TransportState state);

void setPlayMode(PlayMode playMode);

PositionInfo getProgress();

void setProgress(PositionInfo positionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.fourthline.cling.support.avtransport.lastchange.AVTransportLastChangeParser;
import org.fourthline.cling.support.avtransport.lastchange.AVTransportVariable;
import org.fourthline.cling.support.lastchange.LastChange;
import org.fourthline.cling.support.model.PlayMode;
import org.fourthline.cling.support.model.TransportState;
import org.fourthline.cling.workbench.plugins.avtransport.AVTransportControlPoint;
import org.seamless.util.Exceptions;
Expand Down Expand Up @@ -106,6 +107,22 @@ public void run() {
);
}

AVTransportVariable.CurrentPlayMode currentPlayMode =
lastChange.getEventedValue(
instanceId,
AVTransportVariable.CurrentPlayMode.class
);

if (currentPlayMode != null) {
AVTransportControlPoint.LOGGER.fine(
"AVTransport service CurrentPlayMode change to: " + currentPlayMode.getValue());
onPlayModeChange(
new Long(instanceId.getValue()).intValue(),
currentPlayMode.getValue()
);
}


AVTransportVariable.CurrentTrackURI currentTrackURI =
lastChange.getEventedValue(instanceId, AVTransportVariable.CurrentTrackURI.class);
if (currentTrackURI != null) {
Expand All @@ -132,6 +149,8 @@ protected void eventsMissed(GENASubscription subscription, int numberOfMissedEve

abstract protected void onStateChange(int instanceId, TransportState state);

abstract protected void onPlayModeChange(int instanceId, PlayMode playMode);

abstract protected void onCurrentTrackURIChange(int instanceId, String uri);

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import org.fourthline.cling.support.avtransport.callback.Previous;
import org.fourthline.cling.support.avtransport.callback.Seek;
import org.fourthline.cling.support.avtransport.callback.SetAVTransportURI;
import org.fourthline.cling.support.avtransport.callback.SetPlayMode;
import org.fourthline.cling.support.avtransport.callback.Stop;
import org.fourthline.cling.support.model.MediaInfo;
import org.fourthline.cling.support.model.PlayMode;
import org.fourthline.cling.support.model.PositionInfo;
import org.fourthline.cling.support.model.TransportInfo;
import org.fourthline.cling.support.model.TransportState;
Expand Down Expand Up @@ -78,6 +80,11 @@ protected void onStateChange(int instanceId, TransportState state) {
view.getInstanceView(instanceId).setState(state);
}

@Override
protected void onPlayModeChange(int instanceId, PlayMode playMode) {
view.getInstanceView(instanceId).setPlayMode(playMode);
}

@Override
protected void onCurrentTrackURIChange(int instanceId, String uri) {
view.getInstanceView(instanceId).setCurrentTrackURI(uri);
Expand Down Expand Up @@ -316,6 +323,28 @@ public void failure(ActionInvocation invocation,
);
}

@Override
public void onSetPlayModeSelected(final int instanceId, PlayMode playMode) {
controlPoint.execute(
new SetPlayMode(new UnsignedIntegerFourBytes(instanceId), service, playMode) {
@Override
public void success(ActionInvocation invocation) {
AVTransportControlPoint.LOGGER.info(
"Called 'SetPlayMode' action successfully"
);
}

@Override
public void failure(ActionInvocation invocation,
UpnpResponse operation,
String defaultMsg) {
// TODO: Is this really severe?
AVTransportControlPoint.LOGGER.severe("Can't retrieve PositionInfo: " + defaultMsg);
}
}
);
}

public void updateTransportInfo(final int instanceId) {
controlPoint.execute(
new GetTransportInfo(new UnsignedIntegerFourBytes(instanceId), service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.fourthline.cling.workbench.plugins.avtransport.impl;

import org.fourthline.cling.model.ModelUtil;
import org.fourthline.cling.support.model.PlayMode;
import org.fourthline.cling.support.model.PositionInfo;
import org.fourthline.cling.support.model.TransportState;
import org.fourthline.cling.workbench.plugins.avtransport.AVTransportControlPoint;
Expand All @@ -28,6 +29,8 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.net.URI;

/**
Expand All @@ -36,12 +39,14 @@
public class InstanceViewImpl extends JPanel implements InstanceView {

final protected PlayerPanel playerPanel = new PlayerPanel();
final protected PlayModePanel playModePanel = new PlayModePanel();
final protected ProgressPanel progressPanel = new ProgressPanel();
final protected URIPanel uriPanel = new URIPanel();

protected InstanceViewStateMachine viewStateMachine;
protected int instanceId;
protected Presenter presenter;
private ItemListener playModeSpinnerItemListener;

@Override
public void init(int instanceId) {
Expand Down Expand Up @@ -102,10 +107,20 @@ public void actionPerformed(ActionEvent actionEvent) {
@Override
public void actionPerformed(ActionEvent actionEvent) {
presenter.onPlaySelected(getInstanceId());

}
});

playModeSpinnerItemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
final PlayMode playMode = (PlayMode) event.getItem();
presenter.onSetPlayModeSelected(getInstanceId(), playMode);
}
}
};
playModePanel.getPlayModeSpinner().addItemListener(playModeSpinnerItemListener);

progressPanel.getPositionSlider().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
Expand Down Expand Up @@ -144,6 +159,7 @@ public void actionPerformed(ActionEvent actionEvent) {

setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(playerPanel);
add(playModePanel);
add(progressPanel);
add(uriPanel);
}
Expand Down Expand Up @@ -174,6 +190,13 @@ synchronized public void setState(TransportState state) {
}
}

@Override
synchronized public void setPlayMode(PlayMode playMode) {
playModePanel.getPlayModeSpinner().removeItemListener(playModeSpinnerItemListener);
playModePanel.getPlayModeSpinner().setSelectedItem(playMode);
playModePanel.getPlayModeSpinner().addItemListener(playModeSpinnerItemListener);
}

@Override
public PositionInfo getProgress() {
return progressPanel.getPositionInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2013 4th Line GmbH, Switzerland
*
* The contents of this file are subject to the terms of either the GNU
* Lesser General Public License Version 2 or later ("LGPL") or the
* Common Development and Distribution License Version 1 or later
* ("CDDL") (collectively, the "License"). You may not use this file
* except in compliance with the License. See LICENSE.txt for more
* information.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

package org.fourthline.cling.workbench.plugins.avtransport.impl;

import org.fourthline.cling.support.model.PlayMode;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JPanel;

/**
* @author Sebastian Roth
*/
public class PlayModePanel extends JPanel {

class PlayModeSpinner extends JComboBox {
PlayModeSpinner() {
super(PlayMode.values());
}
}

final private PlayModeSpinner playModeSpinner = new PlayModeSpinner();

public PlayModePanel() {
super();

setBorder(BorderFactory.createTitledBorder("Play Mode"));
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

add(Box.createHorizontalGlue());

add(playModeSpinner);

add(Box.createHorizontalGlue());
}

public PlayModeSpinner getPlayModeSpinner() {
return playModeSpinner;
}
}

0 comments on commit 6a686e2

Please sign in to comment.