mikebrady / shairport-sync-metadata-reader

Sample Shairport Sync Metadata Player
MIT License
126 stars 33 forks source link

Skip/new song not working. #25

Closed polmonta closed 3 weeks ago

polmonta commented 1 month ago

Hello there,

I don't know if you are still maintaining this but thank you, this really helped me with my HomeAssistant project :).

I'm just starting in this MQTT world and mostly everything works great, but I've noticed a little bug. When I skip a song, no MQTT message is recieved (in the start_media topic nor the active_start). However, when I resume a song, the MQTT sensors for both the resume and start_media topics turn on.

This is my yaml config:

mqtt:
  sensor:
    - name: "shairport album"
      state_topic: "airplay2/album"
      expire_after: 600

    - name: "shairport artist"
      state_topic: "airplay2/artist"
      expire_after: 600

    - name: "shairport title"
      state_topic: "airplay2/title"
      expire_after: 600

    - name: "shairport genre"
      state_topic: "airplay2/genre"
      expire_after: 600

    - name: "shairport volume (PCT)"
      state_topic: "airplay2/volume"
      value_template: "{{ value | regex_findall_index('^(.+?),', 0) | float / 30 + 1 }}"

  binary_sensor:
    - name: "shairport active start"
      state_topic: "airplay2/active_start"
      payload_on: "--"
      payload_off: "OFF"
      off_delay: 2

    - name: "shairport active end"
      state_topic: "airplay2/active_end"
      payload_on: "--"
      payload_off: "OFF"
      off_delay: 2

    - name: "shairport start media"
      state_topic: "airplay2/play_start"
      payload_on: "--"
      payload_off: "OFF"
      off_delay: 2

    - name: "shairport resume"
      state_topic: "airplay2/play_resume"
      payload_on: "--"
      payload_off: "OFF"
      off_delay: 2

Thank you!

mikebrady commented 1 month ago

Thanks for the message. I'll have to take a look at this...

mikebrady commented 1 month ago

Haven't forgotten...

mikebrady commented 1 month ago

Just looking at this now. The metadata information seems to be coming in from the source alright. So, can you say exactly what you do when you "skip", please? Are you on iOS or Mac? What version of operating system and app, please?

Thanks.

mikebrady commented 1 month ago

...And are you using Shairport Sync in AirPlay 2 or "classic" AirPlay mode? If you could use:

$ shairport-sync -V

and post the response, it would be useful. Thanks.

mikebrady commented 1 month ago

So, as you probably know, MQTT is mostly driven by metadata coming in from the player. You can see this metadata using the shairport-sync-metadata-reader app, especially with the --raw setting.

MQTT sends a play_resume when it receives a prsm metadata message -- you can see the correspondence between metadata and MQTT messages in the mqtt_process_metadata function in matt.c.

When running in "classic" AirPlay mode, the player doesn't send anything like a prsm, a pbeg, so that the reason for this bug you have discovered.

As a potential workaround, track metadata is sent, so maybe you could use a change, say in the track_id, to detect that a new track -- hence a discontinuity like a skip -- has occurred.

polmonta commented 3 weeks ago

I understand now. Thank you for the suggestion!