[chromecast] Added support for next command (#11510)
* feat(chromecast): added support for next command Signed-off-by: Brian O'Connell <boc-tothefuture@users.noreply.github.com>
This commit is contained in:
parent
00ced1d696
commit
edec4c7cf5
@ -55,7 +55,7 @@ Thing chromecast:audiogroup:bathroom [ ipAddress="192.168.0.23", port=42139]
|
|||||||
|
|
||||||
| Channel Type ID | Item Type | Description |
|
| Channel Type ID | Item Type | Description |
|
||||||
|-----------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| control | Player | Player control; currently only supports play/pause and does not correctly update, if the state changes on the device itself |
|
| control | Player | Player control; currently only supports play/pause/next and does not correctly update, if the state changes on the device itself |
|
||||||
| stop | Switch | Send `ON` to this channel: Stops the Chromecast. If this channel is `ON`, the Chromecast is stopped, otherwise it is in another state (see control channel) |
|
| stop | Switch | Send `ON` to this channel: Stops the Chromecast. If this channel is `ON`, the Chromecast is stopped, otherwise it is in another state (see control channel) |
|
||||||
| volume | Dimmer | Control the volume, this is also updated if the volume is changed by another app |
|
| volume | Dimmer | Control the volume, this is also updated if the volume is changed by another app |
|
||||||
| mute | Switch | Mute the audio |
|
| mute | Switch | Mute the audio |
|
||||||
|
|||||||
@ -134,13 +134,6 @@ public class ChromecastCommander {
|
|||||||
|
|
||||||
private void handleControl(final Command command) {
|
private void handleControl(final Command command) {
|
||||||
try {
|
try {
|
||||||
if (command instanceof NextPreviousType) {
|
|
||||||
// I can't find a way to control next/previous from the API. The Google app doesn't seem to
|
|
||||||
// allow it either, so I suspect there isn't a way.
|
|
||||||
logger.info("{} command not yet implemented", command);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Application app = chromeCast.getRunningApp();
|
Application app = chromeCast.getRunningApp();
|
||||||
statusUpdater.updateStatus(ThingStatus.ONLINE);
|
statusUpdater.updateStatus(ThingStatus.ONLINE);
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
@ -166,6 +159,23 @@ public class ChromecastCommander {
|
|||||||
logger.info("{} command not supported by current media", command);
|
logger.info("{} command not supported by current media", command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command instanceof NextPreviousType) {
|
||||||
|
// Next is implemented by seeking to the end of the current media
|
||||||
|
if (command == NextPreviousType.NEXT) {
|
||||||
|
|
||||||
|
Double duration = statusUpdater.getLastDuration();
|
||||||
|
if (duration != null) {
|
||||||
|
chromeCast.seek(duration.doubleValue() - 5);
|
||||||
|
} else {
|
||||||
|
logger.info("{} command failed - unknown media duration", command);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.info("{} command not yet implemented", command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
logger.debug("{} command failed: {}", command, e.getMessage());
|
logger.debug("{} command failed: {}", command, e.getMessage());
|
||||||
statusUpdater.updateStatus(ThingStatus.OFFLINE, COMMUNICATION_ERROR, e.getMessage());
|
statusUpdater.updateStatus(ThingStatus.OFFLINE, COMMUNICATION_ERROR, e.getMessage());
|
||||||
|
|||||||
@ -73,6 +73,9 @@ public class ChromecastStatusUpdater {
|
|||||||
private @Nullable String appSessionId;
|
private @Nullable String appSessionId;
|
||||||
private PercentType volume = PercentType.ZERO;
|
private PercentType volume = PercentType.ZERO;
|
||||||
|
|
||||||
|
// Null is valid value for last duration
|
||||||
|
private @Nullable Double lastDuration = null;
|
||||||
|
|
||||||
public ChromecastStatusUpdater(Thing thing, ChromecastHandler callback) {
|
public ChromecastStatusUpdater(Thing thing, ChromecastHandler callback) {
|
||||||
this.thing = thing;
|
this.thing = thing;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@ -82,6 +85,10 @@ public class ChromecastStatusUpdater {
|
|||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable Double getLastDuration() {
|
||||||
|
return lastDuration;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable String getAppSessionId() {
|
public @Nullable String getAppSessionId() {
|
||||||
return appSessionId;
|
return appSessionId;
|
||||||
}
|
}
|
||||||
@ -186,6 +193,7 @@ public class ChromecastStatusUpdater {
|
|||||||
if (media != null) {
|
if (media != null) {
|
||||||
metadataType = media.getMetadataType().name();
|
metadataType = media.getMetadataType().name();
|
||||||
|
|
||||||
|
lastDuration = media.duration;
|
||||||
// duration can be null when a new song is about to play.
|
// duration can be null when a new song is about to play.
|
||||||
if (media.duration != null) {
|
if (media.duration != null) {
|
||||||
duration = new QuantityType<>(media.duration, Units.SECOND);
|
duration = new QuantityType<>(media.duration, Units.SECOND);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user