Search in sources :

Example 1 with PlayerStatus

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);
    }
}
Also used : MPD(org.bff.javampd.MPD) OnOffType(org.openhab.core.library.types.OnOffType) PlayerStatus(org.bff.javampd.MPDPlayer.PlayerStatus) MPDPlayerException(org.bff.javampd.exception.MPDPlayerException) MPDPlayer(org.bff.javampd.MPDPlayer) ConfigurationException(org.osgi.service.cm.ConfigurationException) MPDConnectionException(org.bff.javampd.exception.MPDConnectionException) MPDResponseException(org.bff.javampd.exception.MPDResponseException) JobExecutionException(org.quartz.JobExecutionException) MPDPlayerException(org.bff.javampd.exception.MPDPlayerException) SchedulerException(org.quartz.SchedulerException) UnknownHostException(java.net.UnknownHostException)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 MPD (org.bff.javampd.MPD)1 MPDPlayer (org.bff.javampd.MPDPlayer)1 PlayerStatus (org.bff.javampd.MPDPlayer.PlayerStatus)1 MPDConnectionException (org.bff.javampd.exception.MPDConnectionException)1 MPDPlayerException (org.bff.javampd.exception.MPDPlayerException)1 MPDResponseException (org.bff.javampd.exception.MPDResponseException)1 OnOffType (org.openhab.core.library.types.OnOffType)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1 JobExecutionException (org.quartz.JobExecutionException)1 SchedulerException (org.quartz.SchedulerException)1