use of org.bff.javampd.MPDPlayer.PlayerStatus in project openhab1-addons by openhab.
the class MpdBinding method determinePlayStateChange.
private void determinePlayStateChange(String playerId) {
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
try {
MPDPlayer player = daemon.getMPDPlayer();
// get the song object here
PlayerStatus ps = player.getStatus();
PlayerStatus curPs = playerStatusCache.get(playerId);
if (curPs != null) {
if (ps != curPs) {
logger.debug("Play state of player '{}' changed", playerId);
playerStatusCache.put(playerId, ps);
PlayerCommandTypeMapping reportTo;
OnOffType reportStatus;
// trigger song update
if (ps.equals(PlayerStatus.STATUS_PAUSED) || ps.equals(PlayerStatus.STATUS_STOPPED)) {
// stopped
reportTo = PlayerCommandTypeMapping.STOP;
reportStatus = OnOffType.OFF;
} else {
// playing
reportTo = PlayerCommandTypeMapping.PLAY;
reportStatus = OnOffType.ON;
}
broadcastPlayerStateChange(playerId, reportTo, reportStatus);
} else {
// nothing, same state
}
} else {
playerStatusCache.put(playerId, ps);
}
} catch (MPDPlayerException pe) {
logger.error("Error while updating player status for player '{}': {}", playerId, pe.getMessage());
} catch (Exception e) {
logger.warn("Failed to communicate with player '{}'", playerId);
}
} else {
logger.warn("Player '{}' was not found or is not connected", playerId);
}
}
Aggregations