Skip to content

Commit

Permalink
Merge pull request #104 from ened/previous-next
Browse files Browse the repository at this point in the history
added previous & play actions to AVTransportControl
  • Loading branch information
Christian Bauer committed Nov 6, 2014
2 parents 5fd60eb + 368a9ec commit e29b545
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 0 deletions.
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.support.avtransport.callback;

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

import java.util.logging.Logger;

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

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

protected Next(ActionInvocation actionInvocation, ControlPoint controlPoint) {
super(actionInvocation, controlPoint);
}

protected Next(ActionInvocation actionInvocation) {
super(actionInvocation);
}

public Next(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}

public Next(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("Next")));
getActionInvocation().setInput("InstanceID", instanceId);
}

@Override
public void success(ActionInvocation invocation) {
log.fine("Execution successful");
}
}
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.support.avtransport.callback;

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

import java.util.logging.Logger;

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

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

protected Previous(ActionInvocation actionInvocation, ControlPoint controlPoint) {
super(actionInvocation, controlPoint);
}

protected Previous(ActionInvocation actionInvocation) {
super(actionInvocation);
}

public Previous(Service service) {
this(new UnsignedIntegerFourBytes(0), service);
}

public Previous(UnsignedIntegerFourBytes instanceId, Service service) {
super(new ActionInvocation(service.getAction("Previous")));
getActionInvocation().setInput("InstanceID", instanceId);
}

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

void onSeekSelected(int instanceId, int deltaSeconds, boolean forwards);

void onPreviousSelected(int instanceId);

void onNextSelected(int instanceId);

void onUpdatePositionInfo(int instanceId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import org.fourthline.cling.support.avtransport.callback.GetMediaInfo;
import org.fourthline.cling.support.avtransport.callback.GetPositionInfo;
import org.fourthline.cling.support.avtransport.callback.GetTransportInfo;
import org.fourthline.cling.support.avtransport.callback.Next;
import org.fourthline.cling.support.avtransport.callback.Pause;
import org.fourthline.cling.support.avtransport.callback.Play;
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.Stop;
Expand Down Expand Up @@ -246,6 +248,49 @@ public void onSeekSelected(int instanceId, int deltaSeconds, boolean forwards) {
onSeekSelected(instanceId, ModelUtil.toTimeString(targetSeconds));
}


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

@Override
public void failure(ActionInvocation invocation,
UpnpResponse operation,
String defaultMsg) {
AVTransportControlPoint.LOGGER.severe(defaultMsg);
}
}
);
}

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

@Override
public void failure(ActionInvocation invocation,
UpnpResponse operation,
String defaultMsg) {
AVTransportControlPoint.LOGGER.severe(defaultMsg);
}
}
);
}

@Override
public void onUpdatePositionInfo(final int instanceId) {
controlPoint.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public void init(int instanceId) {
new Object[]{this}
);

playerPanel.getPreviousButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
presenter.onPreviousSelected(getInstanceId());
}
});

playerPanel.getNextButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
presenter.onNextSelected(getInstanceId());
}
});

playerPanel.getFwdButton().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ protected void run(InstanceViewImpl view) {
view.getPlayerPanel().getStopButton().setEnabled(true);
view.getPlayerPanel().getPlayButton().setEnabled(true);
view.getProgressPanel().getPositionSlider().setEnabled(true);

view.getPlayerPanel().getPreviousButton().setEnabled(true);
view.getPlayerPanel().getNextButton().setEnabled(true);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class PlayerPanel extends JPanel {
public static String[] ACTION_STOP = {"Stop", "avTransportStop"};
public static String[] ACTION_SKIP_FW = {"Skip +15s", "avTransportSkipFW"};
public static String[] ACTION_SKIP_REW = {"Skip -15s", "avTransportSkipREW"};
public static String[] ACTION_PREVIOUS= {"Previous", "avTransportPrevious"};
public static String[] ACTION_NEXT= {"Next", "avTransportNext"};

class PlayerButton extends JButton {
PlayerButton(String text, String icon) {
Expand All @@ -46,11 +48,13 @@ class PlayerButton extends JButton {
}
}

final private PlayerButton previousButton = new PlayerButton(ACTION_PREVIOUS[0], "img/32/player_previous.png");
final private PlayerButton rewButton = new PlayerButton(ACTION_SKIP_REW[0], "img/32/player_rew.png");
final private PlayerButton pauseButton = new PlayerButton(ACTION_PAUSE[0], "img/32/player_pause.png");
final private PlayerButton playButton = new PlayerButton(ACTION_PLAY[0], "img/32/player_play.png");
final private PlayerButton stopButton= new PlayerButton(ACTION_STOP[0], "img/32/player_stop.png");
final private PlayerButton fwdButton = new PlayerButton(ACTION_SKIP_FW[0], "img/32/player_fwd.png");
final private PlayerButton nextButton = new PlayerButton(ACTION_NEXT[0], "img/32/player_next.png");

public PlayerPanel() {
super();
Expand All @@ -60,30 +64,38 @@ public PlayerPanel() {

add(Box.createHorizontalGlue());

add(previousButton);
add(rewButton);
add(stopButton);
add(pauseButton);
add(playButton);
add(fwdButton);
add(nextButton);

add(Box.createHorizontalGlue());

pauseButton.setVisible(false);
}

public void setAllButtons(boolean enabled) {
previousButton.setEnabled(enabled);
rewButton.setEnabled(enabled);
pauseButton.setEnabled(enabled);
playButton.setEnabled(enabled);
stopButton.setEnabled(enabled);
fwdButton.setEnabled(enabled);
nextButton.setEnabled(enabled);
}

public void togglePause() {
playButton.setVisible(!playButton.isVisible());
pauseButton.setVisible(!pauseButton.isVisible());
}

public PlayerButton getPreviousButton() {
return previousButton;
}

public JButton getRewButton() {
return rewButton;
}
Expand All @@ -103,4 +115,8 @@ public JButton getStopButton() {
public JButton getFwdButton() {
return fwdButton;
}

public PlayerButton getNextButton() {
return nextButton;
}
}

0 comments on commit e29b545

Please sign in to comment.