Media-control channel: feeding back status? | ClementineRemote

preface

Hello world :smiley:

I’m a brand new user of OpenHAB and currently developing a new binding to control my favourit media player: Clementine ( clementine-player . org )

For the development, I forked OH 3.3.0 addons on github and am trying to figure some things out.

After some days of reading the docs, reviewing code and scrolling through the community pages I was able to implement the main features:

  • controlling the player (play, pause, next title, previous title, fast forward, rewind, volume)
  • handling the information fed back from the player (info on artist, albrum, track, title, position)

I have implemented playback using the built-in system.media-control channel definition.

However, I have a refinement I wish to implement and don’t know how:

When I have assigned an oh-player-item to my control channel, it’s central button will toggle between a play and pause symbol whenever it is clicked.

This is nice, as it sends alternating PLAY and PAUSE commands to my thing handler, which are then forwarded to the Clementine Player using a protobuf based protocol.

The Clementine player, however, can be put into playing, stopped or paused state directly using it’s UI or another remote control app.

Here is my question:

my problem

How can I make the oh-player-item buttons reflect the players state?

In other words: when I press play on the player’s UI, my ClementineRemoteHandler receives the information that the player software is running a song, but how can the ClementineRemoteHandler update the oh-player-item to display the pause button instead of the play button?

Similar, when I pause (or stop) the player using it’s native UI. The Handler receives the pause (or stop) notification, but how can I make the oh-player-item update to show the play button?


The same holds true for volume control:

Altering the player’s volume using an oh-slider-item via the built-in system.volume channel is implemented and works nicely. However, I have no clue how to update the assigned oh-slider-item when I receive a volume change notification from the player software.

Is this even possible?

Nevermind. I figured it out myself:

For both mentioned channels, I can just update the state via updateState:

For volume feedback:

private void handleVolume(RequestSetVolume message){
    volume = message.getVolume();
    updateState(CHANNEL_CONTROL_VOLUME,new PercentType(volume));
}

similar for media-control:

updateState(CHANNEL_CONTROL_PLAYBACK,state == State.playing ? PlayPauseType.PLAY : PlayPauseType.PAUSE);