How to play mp3 from media browser folder?

This is the script I have and it works perfectly. I didn’t need to whitelist anything.

  - service: media_player.play_media
      entity_id: media_player.speaker
      media_content_id: '/media/local/file.mp3'
      media_content_type: audio/mp3

I had “music” as the media_content_type at first, but it wasn’t working with my setup. I found out using audio/mp3 has no issue.


Here is, what worked for me:

service: media_player.play_media
  media_content_id: /media/music_party/Anastacia - Not that kind.mp3
  media_content_type: music
  entity_id: media_player.fernseher

This is going to a Google Chrome Cast built into my Philips TV.

I had some trouble finding the correct URL for media_content_id. I finally found the right path by using the method described by @antimage in post #7.

When it finally worked, I had no idea where HA took that path segment “/music_party” from. The files are really stored in the /media partition of HA and the folder is called “/Party”. Later I found that the path is actually built using the media_dirs key from configuration yaml:

    music_party: /media/Party

As you can see I did NOT have to put any host in front of the media_content_id, so no problem with host name vs. IP. Also all the authSig token generation and handling mechanics are done automatically in the background. No need to touch that. The param media_content_type works for me with both “music” and “audio/mp3”.


Thats weird.
Playing mp3 in /config/www in my home assistant with “music” works perfectely on old Sonos. However, on a new Sonos or Amazon Echo I got the error “sorry tts can only be called with notify.alexa_media service”. When I use “audio/mp3” or “audio” or “mp3” instead of music, I don’t get anything at all.

If anyone needs python code to generate a “signed” URL to an .mp3 (or some other asset), I wrote this:

from websocket import create_connection
import json
import sys

# Python code to get a "signed path" to a Home Assistant asset via the websocket API
# As per docs:

# Make sure to substitute your server IP, desired path to sign, and long-lived access token
# You can generate your own in HA, click on your username (bottom left) then "Long-Lived Access Tokens" -> "CREATE TOKEN"

host = ""
path_to_sign = "/media/local/doorbell.mp3"
protocol = "http"
access_token = "XXXXXXXX"

ws = create_connection("ws://%s/api/websocket" % host)
    "type": "auth",
    "access_token": access_token
auth_resp = json.loads(ws.recv())
if auth_resp.get('type') != 'auth_ok':
    print('failed to login, check your auth token -- response: %s' % (auth_resp))
      "type": "auth/sign_path",
      "path": path_to_sign,
      "id": 1,
      "expires": 300
    result = json.loads(ws.recv())
    if result.get('success') == True:
        signed_path = result.get('result').get('path')
        print('%s://%s%s' % (protocol, host, signed_path))
        print('ERROR: %s' % result)

The sample above return a URL like:

Note that the generated URL is only valid for 5 minutes

1 Like

How is it supposed to be used?
Do you have an example?

In my case, I am using at /config/www

So I can use http://IP:8123/local/myfile.mp3



  • It is in a public folder.
    I can make Alexa to reproduce it.
service: script.run_alexa_custom_skill_notification
  speech: <audio src="" />
  target: media_player.echo_dot_quarto

Spent a good two hours pulling my hair out on this one. Soin case anyone else stumbles across this, Jpsy has the solution. There’s no token or auth needed. If you have the media folder set up properly in the config it will work.


Does this only work if you select 1 MP3 or can you also select a folder containing multiple MP3s?

Not sure if this will help you guys, but I just started using an Add-on called “Music assistant”. Works pretty well, and casts to all my Chromecast devices MUCH more reliably than Plex. Just thought I’d toss that out there. The interface is remarkably similar to Plex, but it displays right in HA, which is nice. No switching back and forth between apps. :slight_smile:

This deserves more credit. This is the solution that the docs don’t give you.

I did following and it worked for me. I can also play mp3 files from attached USB external HDD

  1. edit configuration.yaml and enter the following lines

- /media
local: /media

  1. I created an automation to play the file. you may be able to use button


  • service: media_player.play_media
    entity_id: media_player.mpd
    media_content_type: audio/mp3
    media_content_id: media-source://media_source/local/Dumps/Songs/Bhajans/Hanuman Chalisa/Hanuman Chalisa - Mahendra Kapoor.mp3
    mode: single

You cannot play a folder or playlist without add-ons. This is because HomeAssist does not stream the media files, but only sends a link to the media file to the speaker, and does not process its contents in any way, so HA does not know the current status, i.e. playback duration. And in order to send the next file from a folder or playlist, you need to know that the previous file has finished playing. Something has to keep track of this, which is why media servers and other additional tools are installed for this purpose.

I use the Music Assistant add-on to serve this purpose. Works AWESOME.