How to change the thumb and title of media_player.play_media without restarting?

I stream radio on a Next hub via a custom link.
I have a script that extracts content artist / title / thumb from the radio’s website.
I know how to set the Title and Thumb when calling the media_player.play_media, but even if I use a template, the content on the Next Hub is static.
Is there a way to update the Title and Thumb without having to call media_player.play_media again (and thus breaking /restarting the sream)?

I currently set the title and Thumb to the radio station but would prefer info about the actual track being streamed

For reference:

    - service: media_player.play_media
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio_speakers", "Master Bedroom Nest Hub") %} media_player.master_bedroom_nest_hub
          {% elif is_state("input_select.chromecast_radio_speakers", "Conservatory") %} media_player.conservatory
          {% elif is_state("input_select.chromecast_radio_speakers", "Kitchen") %} media_player.kitchen
          {% elif is_state("input_select.chromecast_radio_speakers", "Living Room") %} media_player.living_room
          {% elif is_state("input_select.chromecast_radio_speakers", "Office Nest Hub") %} media_player.office_nest_hub
          {% elif is_state("input_select.chromecast_radio_speakers", "House") %} media_player.house
          {% endif %}
        media_content_id: >
          {% if is_state("input_select.chromecast_radio_station", "RTL2") %} http://icecast.rtl2.fr/rtl2-1-44-128
          {% elif is_state("input_select.chromecast_radio_station", "Absolute Radio") %} https://stream-ar.planetradio.co.uk/absoluteradiohigh.aac?direct=true&carrier=unknown&aw_0_1st.bauer_loggedin=false&aw_0_1st.bauer_preroll=1&aw_0_1st.bauer_carrier=unknown&aw_0_req.gdpr=true&aw_0_1st.playerid=BMUK_GoogleHome
          {% elif is_state("input_select.chromecast_radio_station", "Absolute Radio Classic Rock") %} https://stream-ar.planetradio.co.uk/absoluteclassicrockhigh.aac?direct=true&carrier=unknown&aw_0_1st.bauer_loggedin=false&aw_0_1st.bauer_preroll=1&aw_0_1st.bauer_carrier=unknown&aw_0_req.gdpr=true&aw_0_1st.playerid=BMUK_GoogleHome
          {% elif is_state("input_select.chromecast_radio_station", "Hit West") %} http://broadcast.infomaniak.ch/hitwest-high.mp3
          {% elif is_state("input_select.chromecast_radio_station", "HA Podcast") %} {{states("sensor.ha_podcast")}}
          {% elif is_state("input_select.chromecast_radio_station", "IoT Podcast") %} {{states("sensor.internet_of_things_podcast")}}
          {% elif is_state("input_select.chromecast_radio_station", "Chill") %} http://media-the.musicradio.com/ChillMP3
          {% elif is_state("input_select.chromecast_radio_station", "Radio Fiji Two") %} http://peridot.streamguys.com:7150/RFTwo?play
          {% elif is_state("input_select.chromecast_radio_station", "Scala") %}  https://stream-mz.planetradio.co.uk/scalahigh.aac?direct=true&carrier=unknown&aw_0_1st.bauer_loggedin=false&aw_0_1st.bauer_preroll=1&aw_0_1st.bauer_carrier=unknown&aw_0_req.gdpr=true&aw_0_1st.playerid=BMUK_GoogleHome
          {% elif is_state("input_select.chromecast_radio_station", "Navtarang") %} https://stream.fijivillage.com/navtarang
          {% elif is_state("input_select.chromecast_radio_station", "Custom Station") %} {{states("input_text.custom_station")}}
          {% endif %}
        media_content_type: 'audio/mp4'
        extra:
          thumb: >
            {% if is_state("input_select.chromecast_radio_station", "Hit West") %} https://upload.wikimedia.org/wikipedia/fr/b/bd/HitWestLogo.jpg
            {% elif is_state("input_select.chromecast_radio_station", "RTL2") %} http://192.168.9.23:8123/local/RTL2_Logo.png
            {% elif is_state("input_select.chromecast_radio_station", "Absolute Radio") %} https://en.wikipedia.org/wiki/Absolute_Radio#/media/File:AbsoluteLogo.svg
            {% elif is_state("input_select.chromecast_radio_station", "Scala") %} https://media.bauerradio.com/image/upload/tracks/scalaDefaultTrackArt.png
            {% elif is_state("input_select.chromecast_radio_station", "Absolute Radio Classic Rock") %} https://en.wikipedia.org/wiki/Absolute_Radio_Classic_Rock#/media/File:Absolute_Classic_Rock_Logo.png
            {% elif is_state("input_select.chromecast_radio_station", "HA Podcast") %} https://secureimg.stitcher.com/feedimageswide/480x270_176113.jpg
            {% elif is_state("input_select.chromecast_radio_station", "IoT Podcast") %} https://is1-ssl.mzstatic.com/image/thumb/Music62/v4/b3/d6/64/b3d664ab-0560-f24d-2379-d01142267f94/source/1200x630bb.jpg
            {% elif is_state("input_select.chromecast_radio_station", "Chill") %} https://en.wikipedia.org/wiki/Smooth_Chill_(UK_radio_station)#/media/File:Chill_radio_logo.png
            {% elif is_state("input_select.chromecast_radio_station", "Navtarang") %} https://static-media.streema.com/media/cache/61/a2/61a237fb6851e34614c55420b3e11a62.jpg
            {% elif is_state("input_select.chromecast_radio_station", "Radio Fiji Two") %} http://player.streamguys.com/fbc/sgplayer/include/assets/img/RF2.png
            {% elif is_state("input_select.chromecast_radio_station", "Custom Station") %} https://www.holyscripturesandisrael.com/images/radio/radio-icon.png
            {% endif %}
          title: '{{states("input_select.chromecast_radio_station")}}'

This is an old topic, but I’m having this exact question right now. Did you ever find something to implement this?

I’m in the same situation , please Up !

I ran into the same issue, but the solution should be easy:

Instead of streaming the audio in the media player, create a webpage which contains an <audio> object
Then tell chromecast to render the webpage using pychromecast.controllers.dashcast

An example can be found here: https://github.com/AlexxIT/DashCast/blob/a8a16949db75b4134e68d36a3b7233d8ebf4a293/custom_components/dash_cast/__init__.py

Now, instead of needing to update the thumbs in the default media player, you update the webpage layout, eg using AJAX.

Edit: I notice myself that this comes with the disadvantage that the browser based version has autoplay disabled.
This is due to security policy of the built-in chrome browser. This problem is also discussed in other places and there also does not seem to be a solution to this problem. :frowning:

I have a solution to this problem. However, it requires a few changes.

  1. It requires custom code in the cast receiver app that is running in chromecast
  2. To send the required messages to the receiver app, pychromecast needs to be extended
  3. In order to play also local media in a custom receiver app, the receiver app needs to be hosted in the private network. Personally, I serve it directly from home assistant
  4. In order to serve a custom receiver app from the private network, it requires a smart redirect service which redirects chromecast from a public cast URL back into the private network.

I have created all of the above four parts and an example script that shows how to use it.

I have published everything in the following repository: GitHub - Lamarqe/cast-custom-receiver

I have also reached out to the maintainer of pychromecast as I would like to merge the pychromecast extensions back to the main source tree of pychromecast. I am currently waiting for feedback.

1 Like

I have the exact same problem.
I’m trying to set title and thumb using data_template, but sadly I get this error:

"Message malformed: template value should be a string for dictionary value @ data['action'][1]['data_template']"

this is my YAML:
</s> <s>service: media_player.play_media</s> <s>target:</s> <s> entity_id: media_player.glosnik</s> <s>data_template:</s> <s> media_content_id: ></s> <s> {% if is_state('input_select.radio_tmp', 'Radio Pogoda') %}</s> <s> https://radiostream.pl/tuba138-1.mp3</s> <s> {% else if is_state('input_select.radio_tmp', 'Radio ZET') %}</s> <s> https://n-11-21.dcs.redcdn.pl/sc/o2/Eurozet/live/audio.livx</s> <s> {% else %}</s> <s> https://rs101-krk.rmfstream.pl/RMFFM48</s> <s> {% endif %} </s> <s> media_content_type: music</s> <s> extra:</s> <s> title: ></s> <s> {{ states.input_select.radio_tmp.state }}</s> <s> thumb: "https://myradioonline.pl/public/uploads/radio_img/rmf-fm/play_512.webp"</s> <s>

the weird part is that this works:
</s> <s>service: media_player.play_media</s> <s>target:</s> <s> entity_id: media_player.glosnik</s> <s>data:</s> <s> media_content_id: "{{ states.input_text.tmp_url_stacji.state }}"</s> <s> media_content_type: music</s> <s> extra:</s> <s> title: "{{ states.input_select.radio_tmp.state }}"</s> <s> thumb: "{{ states.input_text.tmp_url_miniaturki.state }}"</s> <s>

but when you try to use if/else it throws error

This works just fine:

alias: Ustaw stację
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.radio_tmp
    to: null
condition:
  - condition: template
    value_template: "{{ states.media_player.glosnik.state != \"off\" }}"
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.glosnik
    data:
      media_content_id: >
        {% if is_state('input_select.radio_tmp', 'Radio Pogoda') %}
        https://radiostream.pl/tuba138-1.mp3 {% elif
        is_state('input_select.radio_tmp', 'Radio ZET') %}
        https://n-11-21.dcs.redcdn.pl/sc/o2/Eurozet/live/audio.livx {% else %}
        https://rs101-krk.rmfstream.pl/RMFFM48 {% endif %} 
      media_content_type: music
      extra:
        title: "{{ states.input_select.radio_tmp.state }}"
        thumb: >
          {% if is_state('input_select.radio_tmp', 'Radio Pogoda') %}
          https://myradioonline.pl/public/uploads/radio_img/radio-pogoda/play_512.webp
          {% elif is_state('input_select.radio_tmp', 'Radio ZET') %}
          https://myradioonline.pl/public/uploads/radio_img/radio-zet/play_512.webp
          {% else %}
          https://myradioonline.pl/public/uploads/radio_img/rmf-fm/play_512.webp
          {% endif %} 
mode: single

I had an issue with if/elif/else. I used else if instead of elif.