Offer option to loop/repeat an audio file on the media_player.play_media service

Tags: #<Tag:0x00007f3274bb34a8>

I will try to be short and sweet, as I know the developers of this amazing project have a lot to keep up with.

I have several Google Home speakers dotted throughout the house. I created scripts which are assigned to buttons on Lovelace. When I press the button, whatever speaker it’s assigned to will play a locally hosted audio file with rain sounds. So for example if I press the “bedroom” button, it plays rain sounds on both Google Home Mini speakers in my bedroom.

But these audio files only play for an hour. Yes, I have tried joining them in Audacity but they become too large and therefore do not load well. Further to that, I believe having to do so is a waste of resources on storage, a waste of time, and inefficient since programming a looping function would achieve the same result but quicker and more efficiently (can use smaller files that just loop).

So my request is, can we have a “looping/repeat one” implemented on the media_player.play_media service, or have a brand new media_player.loop_media service created to cater for those of us who need it to play ambient sounds. This would be extremely useful not just to me but others as well, I know there are other people who would make use of this because a quick search for homeassistant media_player loop audio yields several results, and who knows how many more search results would come up by typing the query in different ways since you could describe it differently…

Thank you very much in advance!

I have a file with some snippets of code I’ve collected over the years from this forum. Below is a way of creating looped audio. I know it isn’t the service you are requesting but it should solve your issue in the interim. It’s mostly copy / pasted and from a long time ago so might need a few checks, I haven’t used it myself

script: 
  - alias: Fire Alarm
      sequence:
        - service: media_player.volume_set
          data:
            entity_id: media_player.kitchen_speaker, media_player.googlehome1023
            volume_level: '0.90'
        - service: tts.google_say
          data:
            entity_id: media_player.kitchen_speaker, media_player.googlehome1023
            message: 'Fire Alarm, Evacuate'
        - delay:
            seconds: 2
        - service: media_player.play_media
          data:
            entity_id: media_player.kitchen_speaker, media_player.googlehome1023
            media_content_id: https://xxxxxxxxxxxx/local/submarine_diving_alarm.mp3
            media_content_type: 'audio/mp3'
        - delay:
            seconds: 1   
        - service: script.turn_on
          data:
            entity_id: script.fire_alarm_loop
      
    
  - alias: Fire Alarm loop
      sequence:
        - delay:
            # time for light off
            seconds: 2
        - service: script.turn_on
          data:
            entity_id: script.fire_alarm

Thanks, I have found bits and pieces of code around the forum (now yours is another one to add to the list). As you can imagine, for a novice it would be a nightmare figuring out what to do… so I thought suggesting this feature would help more than just myself (as well as making life easier). Hoping someone can implement it, if I knew how to program I would be doing it right away! Stay safe.

Bump

I can’t believe I’m the only person who finds this a valuable addition crying

Bump - please vote? Thanks!

Bump please vote y’all :heart:

I’d like to know this too. There is media_player.repeat_set which from the docs looks like should be able to set to all or one to make a player repeat but this has not worked for me (when calling this on a playing media_player)