From 368a9ece3064bd12af83f292f8d9adb257bc1cc4 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Thu, 6 Nov 2014 18:26:42 +0800 Subject: [PATCH] added previous & play actions to AVTransportControl --- .../support/avtransport/callback/Next.java | 55 +++++++++++++++++++ .../avtransport/callback/Previous.java | 55 +++++++++++++++++++ .../plugins/avtransport/InstanceView.java | 4 ++ .../impl/AVTransportPresenter.java | 45 +++++++++++++++ .../avtransport/impl/InstanceViewImpl.java | 14 +++++ .../plugins/avtransport/impl/PausedPlay.java | 3 + .../plugins/avtransport/impl/PlayerPanel.java | 16 ++++++ 7 files changed, 192 insertions(+) create mode 100644 support/src/main/java/org/fourthline/cling/support/avtransport/callback/Next.java create mode 100644 support/src/main/java/org/fourthline/cling/support/avtransport/callback/Previous.java diff --git a/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Next.java b/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Next.java new file mode 100644 index 000000000..6c756563d --- /dev/null +++ b/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Next.java @@ -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"); + } +} \ No newline at end of file diff --git a/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Previous.java b/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Previous.java new file mode 100644 index 000000000..ae3b80d06 --- /dev/null +++ b/support/src/main/java/org/fourthline/cling/support/avtransport/callback/Previous.java @@ -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"); + } +} \ No newline at end of file diff --git a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/InstanceView.java b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/InstanceView.java index 4e614b179..f77593531 100644 --- a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/InstanceView.java +++ b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/InstanceView.java @@ -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); } diff --git a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/AVTransportPresenter.java b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/AVTransportPresenter.java index 5a8f0d2c1..5b2f6adba 100644 --- a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/AVTransportPresenter.java +++ b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/AVTransportPresenter.java @@ -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; @@ -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( diff --git a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/InstanceViewImpl.java b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/InstanceViewImpl.java index 0c82ea9c0..6f3382dfa 100644 --- a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/InstanceViewImpl.java +++ b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/InstanceViewImpl.java @@ -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) { diff --git a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PausedPlay.java b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PausedPlay.java index 49590d7fb..96d2fbfff 100644 --- a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PausedPlay.java +++ b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PausedPlay.java @@ -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); } }; } diff --git a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PlayerPanel.java b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PlayerPanel.java index 3e0064d69..332e3e301 100644 --- a/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PlayerPanel.java +++ b/workbench/src/main/java/org/fourthline/cling/workbench/plugins/avtransport/impl/PlayerPanel.java @@ -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) { @@ -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(); @@ -60,11 +64,13 @@ public PlayerPanel() { add(Box.createHorizontalGlue()); + add(previousButton); add(rewButton); add(stopButton); add(pauseButton); add(playButton); add(fwdButton); + add(nextButton); add(Box.createHorizontalGlue()); @@ -72,11 +78,13 @@ public PlayerPanel() { } 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() { @@ -84,6 +92,10 @@ public void togglePause() { pauseButton.setVisible(!pauseButton.isVisible()); } + public PlayerButton getPreviousButton() { + return previousButton; + } + public JButton getRewButton() { return rewButton; } @@ -103,4 +115,8 @@ public JButton getStopButton() { public JButton getFwdButton() { return fwdButton; } + + public PlayerButton getNextButton() { + return nextButton; + } }