@Override public void dispose() { // stop our duration counter if (timeCounterJob != null && !timeCounterJob.isCancelled()) { timeCounterJob.cancel(true); timeCounterJob = null; } if (squeezeBoxServerHandler != null) { squeezeBoxServerHandler.removePlayerCache(mac); } logger.debug("Thing {} disposed.", getThing().getUID()); super.dispose(); }
/** Helper method to mute a players */ private void mute() { unmuteVolume = currentVolume(); squeezeBoxServerHandler.mute(mac); }
@Override public void handleCommand(ChannelUID channelUID, Command command) { if (squeezeBoxServerHandler == null) { logger.warn("Player has no server configured, ignoring command"); return; } String mac = getConfigAs(SqueezeBoxPlayerConfig.class).mac; switch (channelUID.getIdWithoutGroup()) { case CHANNEL_POWER: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.powerOn(mac); } else { squeezeBoxServerHandler.powerOff(mac); } break; case CHANNEL_MUTE: if (command.equals(OnOffType.ON)) { mute(); } else { squeezeBoxServerHandler.unMute(mac, unmuteVolume); } break; case CHANNEL_STOP: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.stop(mac); } else if (command.equals(OnOffType.OFF)) { squeezeBoxServerHandler.play(mac); } break; case CHANNEL_PLAY_PAUSE: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.play(mac); } else if (command.equals(OnOffType.OFF)) { squeezeBoxServerHandler.pause(mac); } break; case CHANNEL_PREV: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.prev(mac); } break; case CHANNEL_NEXT: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.next(mac); } break; case CHANNEL_VOLUME: if (command instanceof PercentType) { squeezeBoxServerHandler.setVolume(mac, ((PercentType) command).intValue()); } else if (command.equals(IncreaseDecreaseType.INCREASE)) { squeezeBoxServerHandler.volumeUp(mac, currentVolume()); } else if (command.equals(IncreaseDecreaseType.DECREASE)) { squeezeBoxServerHandler.volumeDown(mac, currentVolume()); } else if (command.equals(OnOffType.OFF)) { mute(); } else if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.unMute(mac, unmuteVolume); } break; case CHANNEL_CONTROL: if (command instanceof PlayPauseType) { if (command.equals(PlayPauseType.PLAY)) { squeezeBoxServerHandler.play(mac); } else if (command.equals(PlayPauseType.PAUSE)) { squeezeBoxServerHandler.pause(mac); } } if (command instanceof NextPreviousType) { if (command.equals(NextPreviousType.NEXT)) { squeezeBoxServerHandler.next(mac); } else if (command.equals(NextPreviousType.PREVIOUS)) { squeezeBoxServerHandler.prev(mac); } } if (command instanceof RewindFastforwardType) { if (command.equals(RewindFastforwardType.REWIND)) { squeezeBoxServerHandler.setPlayingTime(mac, currentTime() - 5); } else if (command.equals(RewindFastforwardType.FASTFORWARD)) { squeezeBoxServerHandler.setPlayingTime(mac, currentTime() + 5); } } break; case CHANNEL_STREAM: squeezeBoxServerHandler.playUrl(mac, command.toString()); break; case CHANNEL_SYNC: if (StringUtils.isBlank(command.toString())) { squeezeBoxServerHandler.unSyncPlayer(mac); } else { squeezeBoxServerHandler.syncPlayer(mac, command.toString()); } case CHANNEL_UNSYNC: if (command.equals(OnOffType.ON)) { squeezeBoxServerHandler.unSyncPlayer(mac); } break; case CHANNEL_PLAYLIST_INDEX: squeezeBoxServerHandler.playPlaylistItem(mac, ((DecimalType) command).intValue()); break; case CHANNEL_CURRENT_PLAYING_TIME: squeezeBoxServerHandler.setPlayingTime(mac, ((DecimalType) command).intValue()); break; case CHANNEL_CURRENT_PLAYLIST_SHUFFLE: squeezeBoxServerHandler.setShuffleMode(mac, ((DecimalType) command).intValue()); break; case CHANNEL_CURRENT_PLAYLIST_REPEAT: squeezeBoxServerHandler.setRepeatMode(mac, ((DecimalType) command).intValue()); break; default: break; } }