Mediaplayer Now Playing and Control

A list widget that combines track, artist, playback service, and play controls into one widget. The widget is based on the Channels provided by the Chromecast binding but should support most media players. When the player is idling, the widget will be hidden.

The widget has the following properties:

Property Purpose
Player Name Used as the title of the widget, if not defined there will be no title.
Item Prefix An optional Item name prefix which is used to generate the names of all the Items based on the naming scheme below. If you use this property you do not need to select the individual Items. If you use this property you can override the prefix with a different Item name by selecting the individual Item below. “Unknown” will be shown in the widget if neither the prefix nor the Item is selected.
Application Select the String Item that has the name of the application currently playing media on the device. Selecting this overrides the prefix Item if the prefix is set.
Media Title Select the String Item that has the title of the media currently playing. Selecting this overrides the prefix Item if the prefix is set.
Media Artist Select the String Item that has the artist of the media currently playing. Selecting this overrides the prefix Item if the prefix is set.
Media Control Select the Player Item that controls the media playback. Selecting this overrides the prefix Item if the prefix is set.
Visibility Select the Switch Item which, when ON, should cause this widget to be hidden. If neither the prefix nor this property are set, the widget is always shown and never hidden.

The widget can work using an Item name prefix so you must name your Items with a common prefix. The last part of the name of the Items should be:

  • <Prefix>_MediaTitle : name of the media playing
  • <Prefix>_MediaArtist : name of the artist
  • <Prefix>_Idling : Switch Item that is set to true when the player is not playing anything
  • <Prefix>_App : The name of the app currently playing
  • <Prefix>_MediaControl : a Player type Item to control play, pause, fast forward and rewind

Note, the prefix property and this naming scheme is kept for backwards compatibility. When using the default naming schemes for Items when generating Items using “add equipment from thing” et al the naming of the Items is actually different now using _ instead of camel case. So the prefix property will mainly be useful for legacy users of this widget.

Changelog

Version 0.2

  • Updated to use the new(ish) @ syntax for getting the Item states
  • Added properties to individually select the Items that go for each property.
  • If no visibility Item and no prefix is defined, visibility is set to always show the widget.

Version 0.1

  • initial release

Resources

uid: rlk_media_control_list
tags:
  - list
  - media
props:
  parameters:
    - description: Player name
      label: Name
      name: name
      required: false
      type: TEXT
    - description: An optional prefix to item names instead of selecting all the items individually. The names need to be the prefix plus _MediaTitle, _MediaArtist, _Idling, _App, and _MediaControl.
      label: Item Prefix
      name: prefix
      required: false
      type: TEXT
    - context: item
      description: String item with the name of the application currently playing media that is used when prefix is not defined.
      label: Application
      name: app
      required: false
      type: TEXT
      filterCriteria:
        - value: String
          name: type
    - context: item
      description: String item with the title of the media currently playing that is used when prefix is not defined.
      label: Media Title
      name: title
      required: false
      type: TEXT
      filterCriteria:
        - value: String
          name: type
    - context: item
      description: String item with the artist of the media currently playing that is used when prefix is not defined.
      label: Media Artist
      name: artist
      required: false
      type: TEXT
      filterCriteria:
        - value: String
          name: type
    - context: item
      description: Player item that can control this device that is used when prefix is not defined.
      label: Media Control
      name: control
      required: false
      type: TEXT
      filterCriteria:
        - value: Player
          name: type
    - context: item
      description: Switch item that controls the visibility of this widget. When the Item is OFF the widget is hidden that is used when prefix is not defined.. If both the prefix and this property are undefined the default is to always show the widget.
      label: Visibility
      name: visibility
      required: false
      type: TEXT
      filterCriteria:
        - value: Switch
          name: type
timestamp: Feb 7, 2024, 1:35:04 PM
component: oh-player-item
config:
  icon: f7:hifispeaker
  iconColor: black
  title: '=(props.name === undefined) ? "" : props.name'
  subtitle: '=((props.title !== undefined) ? @props.title : (props.prefix !== undefined) ? @(props.prefix + "_MediaTitle") : "unknown") + " by " + ((props.artist !== undefined) ? @props.artist :(props.prefix !== undefined) ? @(props.prefix + "_MediaArtist") : "unknown")'
  visible: '=(props.visibility !== undefined) ? (items[props.visibility].state != "ON") : (props.prefix !== undefined) ? (items[props.prefix + "_Idling"].state != "ON") : true'
  trackItem: '=(props.title !== undefined) ? props.title : (props.prefix !== undefined) ? props.prefix + "_MediaTitle" : ""'
  after: '=(props.app !== undefined) ? @props.app : (props.prefix !== undefined) ? @(props.prefix + "_App") : "unknown"'
  artistItem: '=(props.prefix !== undefined) ? props.prefix + "_MediaArtist" : ""'
  showRewindFFward: false
  item: '=(props.control) ? props.control : (props.prefix !== undefined) ? props.prefix + "_MediaControl" : ""'
1 Like

hi ,nice work there mate,i was looking for a simple player widget for my audiogroup.I just add it to my Overview page and i get this

i cant get what am i doing wrong

and i wonder how can i add a volume slider too :slight_smile:

It’s a list item widget. It’s intended to be included as one entry in a list-card (e.g. like the Location cards on the overview page. It’s not a stand alone widget.

I wasn’t good enough to do that in a list Item widget at the time so I used a separate widget. However, I’ve since learned how to do that but I don’t really use this widget so I’ve never updated it. I can add it to my list to of todos, but it’s not super high on the list.

But that won’t help you much. You still won’t be able to add it as a stand alone widget.

What happens if you put showRewindFFward to true? Is it possible to have a rewind and a fast forward button?

One of the most frustrating things is in the time it took to create this message and the time it’ll take me to reply you could have just tried it to see what happens.

I don’t know what happens if you put showRewindFFward to true. If I remember correctly, Chromecast doesn’t support FF/RW but that was years ago. Give it a try and find out.

My apologies. My wording was indeed less than ideal.

My underlying message was that if I put it on true , nothing happens. But maybe that’s different with you? Is there a way to integrate rewind an fast forward in a widget?

In that case I it might be something that isn’t supported or supported differently from browser to browser.

I don’t know. I know that Chromecasts do not support any sort of separate fast forward command.

Just a note that with auto generated items in latest openHAB versions this now needs to be

item: =props.prefix + "_Media_Control"

Older openHAB used the widget codes way, now it adds the underscore for anyone that uses ‘create equipment from thing’ to auto create the items.

@rlkoshak What is the best way to now handle this as people may have items created a long time ago but want to download the widget for the first time today? Do we change widgets as we now have a large amount of widgets that were working, and break for new users?

That’s one choice but not the only one.

You can add versioning to the title of the post (e.g. [3.2.0;3.4.9] would cover all OH versions between 3.2.0 and 3.4.9, [4.0.0.0;4.9.9.9] would cover all versions of OH 4). Then create a new post with the changes for new versions of OH. Only the version compatible with the version of OH the user is running will appear in the add-on store.

It’s not perfect (I’ve had more than one user of rule templates get confused by the two postings) but it’s better than nothing.

I don’t think that’s needed for this widget though. I wonder if it might not be better to get rid of the prefix and just have the users select the individual Items as properties in the first place. That would be forward and backward compatible (kind of, if the user updates the widget with the new one they’ll have to reconfigure it where it’s being used to supply the new properties) and work better with Item naming schemes that may be different than come from Chromecasts. But it does add a tiny bit more work to the end users.

This was one of my very first complex widgets so it’s reasonable I think to give it a refresh.

Thanks for the ideas and info.

I have a new binding I am working on and I am designing it back to front, looking at widgets to see what is possible and then designing the binding to fit with an end goal I want to see. Having widgets that work with more use cases is better and if its not perfect, it can then make other peoples lives easier by providing a copy paste source for them to build from.

Learning a lot from your list widgets as its a different way to my go to thought process. Thanks.

1 Like

I’ll be updating this one over the next couple of days. I’ll also review my other ones to see if they need a similar refresh. Thanks for pointing out the differences in naming!

The widget has been updated. It supports both the prefix in the legacy way and supports selecting the Items individually. If both the prefix and an Item is selected individually, the selected Item takes precedence. I think this strikes a balance between backwards compatibility and supporting more than just Chromecast Items.

2 Likes