Chromecast Binding - How to send STOPMOVETYPE


(Chris Colden) #1

Hi,

Been looking for a way to stop the chromecasts and exit the app thats running. When reviewing the code for the binding I see that the control handler accepts a STOPMOVETYPE which calls the required method in the chromecast api to exit the app on the device.

My issue is, that the Control channel excepts a player item and the player item doesn’t take a stopmovetype so I have no idea how it is possible to send a STOP command.

Below i have extracted the relevant code from the ChromecastCommander.java

    public void handleCommand(final ChannelUID channelUID, final Command command) {
        if (chromeCast == null) {
            return;
        }

        if (command instanceof RefreshType) {
            handleRefresh();
            return;
        }

        switch (channelUID.getId()) {
            case CHANNEL_CONTROL:
                handleControl(command);
                break;
            case CHANNEL_VOLUME:
                handleVolume(command);
                break;
            case CHANNEL_MUTE:
                handleMute(command);
                break;
            case CHANNEL_PLAY_URI:
                handlePlayUri(command);
                break;
            default:
                logger.debug("Received command {} for unknown channel: {}", command, channelUID);
                break;
        }
    }
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;
            }

            Application app = chromeCast.getRunningApp();
            statusUpdater.updateStatus(ThingStatus.ONLINE);
            if (app == null) {
                logger.debug("{} command ignored because media player app is not running", command);
                return;
            }

            if (command instanceof StopMoveType) {
                final StopMoveType stopMoveType = (StopMoveType) command;
                if (stopMoveType == StopMoveType.STOP) {
                    chromeCast.stopApp();
                    statusUpdater.updateMediaStatus(null);
                }
                return;
            }

            if (command instanceof PlayPauseType) {
                MediaStatus mediaStatus = chromeCast.getMediaStatus();
                logger.debug("mediaStatus {}", mediaStatus);
                if (mediaStatus == null || mediaStatus.playerState == MediaStatus.PlayerState.IDLE) {
                    logger.debug("{} command ignored because media is not loaded", command);
                    return;
                }

                final PlayPauseType playPause = (PlayPauseType) command;
                if (playPause == PlayPauseType.PLAY) {
                    chromeCast.play();
                } else if (playPause == PlayPauseType.PAUSE
                        && ((mediaStatus.supportedMediaCommands & 0x00000001) == 0x1)) {
                    chromeCast.pause();
                } else {
                    logger.info("{} command not supported by current media", command);
                }
            }
        } catch (final Exception e) {
            logger.debug("{} command failed: {}", command, e.getMessage());
            statusUpdater.updateStatus(ThingStatus.OFFLINE, COMMUNICATION_ERROR, e.getMessage());
        }
    }

Just trying to work out if this should be logs as an issue with the binding, or if i’m just being dumb.

Thanks
Chris


(Christoph Weitkamp) #2

Hi Chris,

The only Item I am aware of which accepts a StopMoveType is a Rollershutter item. From my point of view it does not make sense to link it to the control channel. Furthermore I think the current implementation should be removed from the binding. Rather implement a dedicated stop channel of item type Switch which is the way how we did it in other media control bindings (e.g. Kodi).

You can try to link a String item and either send a “STOP” command via rule or implement a Switch element using a mapping in a sitemap. But I am afraid they will not be recognized as StopMoveType.


(Chris Colden) #3

So were saying this code in the binding has been implemented incorrectly? If so I will create an issue for it.


(Christoph Weitkamp) #4

I would vote for: Yes.