Lovelace: Mini Media Player

I have cobbled something together on my local machine, which seems to be in line with the requirements you mention. The results that I get for the master:

volume_level: 0.25
is_volume_muted: false
media_content_type: music
media_position: 127.45142799999999
media_position_updated_at: 2019-10-23T06:42:22.552787+00:00
media_title: De muziek zegt alles - Hilversum
media_artist: Clarence Clemons&Jackson Browne - You're A Friend Of Mine
media_album_name: NPO Radio 2
source: 92.6 | NPO Radio 2 (Adult Hits)
source_list: 98.9 | NPO Radio 1 (Talk),92.6 | NPO Radio 2 (Adult Hits),96.8 | NPO 3FM (Top 40 & Pop Music),94.3 | NPO Radio 4 (Classical Music),Library,Amazon Music,Radio Paradise,TuneIn,Bluetooth,Optical Input,Spotify
shuffle: false
bluesound_group: bluesound_achterkamer,bluesound_voorkamer
is_master: true
friendly_name: bluesound_achterkamer
icon: /images/players/N180_nt.png
entity_picture: /api/media_player_proxy/media_player.bluesound_achterkamer?token=...&cache=...
supported_features: 65085

and for the slave:

volume_level: 0.35
is_volume_muted: false
media_content_type: music
media_position_updated_at: 2019-10-23T06:42:22.549920+00:00
media_artist: Achterkamer+Voorkamer
shuffle: false
bluesound_group: bluesound_achterkamer,bluesound_voorkamer
is_master: false
friendly_name: bluesound_voorkamer
icon: /images/players/P125_nt.png
supported_features: 1036

When the group no longer exists, the bluesound_group attribute is no longer present. While this works nicely on my local machine, I am not able to test with multiple groups or groups larger than 2 as I only have two devices
 Would this work in its current form for the mini-media-player?

1 Like

Hi @kalkih

Thx for the hint. I have no idea why but the card is now working as it should (without adding your suggested fix). No clue what happened or why it suddenly works as expected :-).

Best & thx,
Marc

1 Like

That’s amazing, well done!
Just from looking at the attributes, yes that should do it.
Are you planning on submitting these changes in a PR to the HA repo?

That’s great to hear, I still wonder what caused the issue in the first place :thinking:
Anyway, great that it works now!

Yes, I’ll give that a try. Have not done this before (and I’m also not a big-shot star-studded python hero), so all takes some time for me to read-up on how to get things done. Repo is forked, changes committed to local feature branch, now need to create the PR and submit.

1 Like

For reference: PR created. Slight change with respect to output mentioned above is that master is used instead of is_master. Otherwise the output should be identical to what was mentioned earlier in the conversation.

1 Like

Nicely done!

Just a curiosity.

Why these two cards have different background color also if the config is the same?
The first two are sonos group with speaker_group option, the third is only a group card.

59

From the docs:

| group | boolean | optional | v0.1 | Removes paddings, background color and box-shadow.

Ok, so it’s valid also for non-sonos groups?
EDIT: i have group option to true in all the cards, but only in sonos group i have that behaviour

Or maybe i don’t understand well what the docs state.

The group option have nothing to do with sonos or speaker_group.

Okay, I’ll try to explain it clearer.

All cards are transparent, as a result of group: true and the cards will therefore have the same background color as the background behind the card, the cards are transparent, right?

The third card looks to be nested inside another card which seem to have a background-color set, the mini-media-player card is transparent and as a result you can see the underlaying card and it’s background-color right through it.

Is there any possibility of adding skip 30 seconds forward and backward buttons?u4a2hc5zgt211

The seek bar functionality works great but I can never get the exact 30 seconds correct using the bar.

Otherwise I quite enjoy using this card.

Thanks

Ok thanks, now it’s clearer
 the third card is nested inside an entities card, that’s why i get that background!

1 Like

That’s a good fit for the shortcuts, have the shortcuts call a script with the entity_id and possibly skip_interval as parameters and handle the service call from the script, that way you can reuse the same script in multiple cards or places.

Let me know if you need help with a concrete example.

Yes, a general skip script would be ideal. The problem is I don’t know how to get the progress and duration from the media_player entity. I believe media player only accepts seek_position which is an absolute position in the track, not an interval.

The magic of your card exposes the progress and duration of the track so that a 30 second skip can be calculated and seek_position can be used to skip.

Maybe we could get the HA people to code a seek_interval service call.

Am I missing an easy way to do this in a script?

1 Like

Yes, I need help, thanks!

Okay, this is what I got, what do you think?

The script

skip:
  alias: skip
  sequence:
    - service: media_player.media_seek
      data_template:
        entity_id: "{{ entity }}"
        seek_position: "{{ state_attr(entity, 'media_position') | float + interval }}"

The card

- type: custom:mini-media-player
  entity: media_player.example
  shortcuts:
    buttons:
      - type: script
        id: skip
        icon: mdi:rewind-10
        data:
          entity: media_player.example # Same as card entity
          interval: -10 # Skip in seconds (change by preference)
      - type: script
        id: skip
        icon: mdi:fast-forward-10
        data:
          entity: media_player.example # Same as card entity
          interval: 10 # Skip in seconds (change by preference)

04

This will only work for media players reporting the media_position.
And it will throw an error if media_position + interval < 0 but it’s a good start.

1 Like

Amazing! Thanks!

I can’t believe that I didn’t know that media_position was in the state attributes.

I think I’ll have to use the media_position_updated_at attribute as well because the media_position doesn’t seem to be the current position but the position last time the attributes were updated. Not sure why it doesn’t stay up to date.

1 Like

That’s a smart idea, that’s actually how we calculate and track the progress in the mini-media-player card, some platforms seem to keep it pretty up to date and some less so, for performance reasons I guess. :slightly_smiling_face: