Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chromecast] Added support for next command #11510

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.chromecast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Thing chromecast:audiogroup:bathroom [ ipAddress="192.168.0.23", port=42139]

| 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) |
| volume | Dimmer | Control the volume, this is also updated if the volume is changed by another app |
| mute | Switch | Mute the audio |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,19 @@ private void handlePlayUri(Command command) {
private void handleControl(final Command command) {
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;
// Next is implemented by seeking to the end of the current media
if (command == NextPreviousType.NEXT) {
lolodomo marked this conversation as resolved.
Show resolved Hide resolved

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;
}
}

Application app = chromeCast.getRunningApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class ChromecastStatusUpdater {
private @Nullable String appSessionId;
private PercentType volume = PercentType.ZERO;

// Null is valid value for last duration
private @Nullable Double lastDuration = null;

public ChromecastStatusUpdater(Thing thing, ChromecastHandler callback) {
this.thing = thing;
this.callback = callback;
Expand All @@ -82,6 +85,10 @@ public PercentType getVolume() {
return volume;
}

public @Nullable Double getLastDuration() {
return lastDuration;
}

public @Nullable String getAppSessionId() {
return appSessionId;
}
Expand Down Expand Up @@ -186,6 +193,7 @@ private void updateMediaInfoStatus(final @Nullable Media media) {
if (media != null) {
metadataType = media.getMetadataType().name();

lastDuration = media.duration;
// duration can be null when a new song is about to play.
if (media.duration != null) {
duration = new QuantityType<>(media.duration, Units.SECOND);
Expand Down