Media playback [Solved]

Hello, this is a very basic question but I couldn’t seem to get it working.

I have a local file at www folder named “test.mp3” and trying to play this file from a media player, I used vlc and mpc.

  action:   
    service: media_player.play_media
    data:
      entity_id: media_player.testsound
      media_content_id: '/local/test.mp3'
      media_content_type: 'audio/mp3'

I’ve also tried:

  action:   
    service: media_player.play_media
    data:
      entity_id: media_player.testsound
      media_content_id: '/local/test.mp3'
      media_content_type: 'music'

I also tried the service with this code:

{ "data": {"media_content_id":"/local/test.mp3","media_content_type":"audio/mp3"} }

I keep getting the error:

ERROR (MainThread) [homeassistant.core] Invalid service data for media_player.play_media: extra keys not allowed @ data['data']. Got {'media_content_id': '/local/test.mp3', 'media_content_type': 'music'}
required key not provided @ data['media_content_id']. Got None
required key not provided @ data['media_content_type']. Got None

Thank you

1 Like

Hi,

You need to specify in the “media_Content_id” the full path of the audio file.
Something like: /home/pi/homeassistant/www/songs/test.mp3

Have a good day

Nik

Your syntax looks fine to me, the “/local/test.mp3” path should also not give any problems.
Can you try an online file to see if it works?

    service: media_player.play_media
      data:
        entity_id: media_player.home_group
        media_content_id: https://dl.dropboxusercontent.com/s/cv0u9tsp327n3u7/T99.mp3?dl=0
        media_content_type: 'audio/mp3'
2 Likes

Hello,

The fix included:

media_player:
  - platform: vlc
    name: testsound
    arguments: '--alsa-audio-device=hw:0,0'

This sets the output to audio jack and not the hdmi. Which fixed the actual problem.

Both your examples are correct by the way. @Gilganik yeah setting "/local/test.mp3" does not work, as you said "/home/pi/.homeassistant/www/test.mp3" has to be used.
but @Bob_NL you have to use media_content_type: 'music' otherwise it won’t work.

Thanks everyone.

1 Like

media_content_type: ‘audio/mp3’ and ‘audio/mp4’ both working fine here.

Try this in services:

{ "entity_id" : "media_player.xxxxx", "media_content_id": "https://dl.dropboxusercontent.com/s/cv0u9tsp327n3u7/T99.mp3?dl=0", "media_content_type":"audio/mp3"} 

mine gives error:
[homeassistant.components.media_player.vlc] Invalid media type audio/mp3. Only music is supported

My media player is vlc and I am on HA version 0.53.1 by the way.

Perhaps it has something to do with VLC, I’m using Chromecasts.

Edit: jep that’s it:
https://home-assistant.io/components/media_player.vlc/

Only the “music” media type is supported for now.

Thank you for the clarification.

Not sure what music type does but this works.

- service: media_player.play_media
  data:
    entity_id: media_player.speaker
    media_content_id: /home/pi/Downloads/play.mp3
    media_content_type: 'music'
2 Likes

Anybody any idea what would be the media_content_id of a Google Play music playlist or the “I feel lucky” functionality? Or isn’t that possible because of the authentication?

1 Like

For the aid of others reading this post later. I have had I problem with getting media_player.play_media to work. And I finally figured out that the media file name is case sensitive. So what you have here in the second example works:
media_content_type: 'music'
but ensure the file path is correct including the Case.

How do I install VLC on HassOs?
I want to play tts locally, its on a PC with VMWare, and i would like to play tts in the speakers, is it possible?

Thanks!

Hi, i tries everything like you but i didn’t figure out the issue.
my script in scripts.yaml is

perdita_acqua_cucina:
  alias: perdita acqua cucina notifica vocale
  sequence:
  - service: media_player.play_media
    data:
    entity_id: media_player.google_home_mini_sala
    media_content_id: https://192.168.0.14:8123/local/config/www/Audio/Siren.mp3 #sftp://[email protected]/config/www/Audio/Siren.mp3 this is the path of the mp3 from #filezilla
    media_content_type: 'music'

Really i tried everything, can you give me some advice?
Thanks

The correct way is:

media_content_id: local:track:misc/xxx.mp3
media_content_type: music

Where “misc/” is a subdirectory inside

media_dir = /share/mopidy/media
1 Like

If locally downloaded and stored in externally accessible folder, eg: www/media/PoliceSireneYT=Jr0HpAENhTM.mp4:

service: media_player.play_media
data:
  media_content_id: /local/media/PoliceSireneYT=Jr0HpAENhTM.mp4
  media_content_type: video
entity_id: media_player.hub

when using from youtube directly using Media Extractor (seems even faster to cast),

service: media_extractor.play_media
data:
  entity_id: media_player.hub
  media_content_id: 'https://www.youtube.com/watch?v=Jr0HpAENhTM'
  media_content_type: video/youtube

Hi All, What’s wrong with this:

type: button
tap_action:
  action:
    service: media_player.play_media
    data:
      entity_id: media_player.stue_ac
      media_content_id: https://p7.p4groupaudio.com/P07_MH
      media_content_type: music
entity: media_player.stue_ac

If I use the service tab under developer tools, and enter the exact same, it works just fine.
I am so frustrated. Please help.

Its not data but service data

try this

type: button
tap_action:
  action:
    service: media_player.play_media
    service_data:
      entity_id: media_player.stue_ac
      media_content_id: https://p7.p4groupaudio.com/P07_MH
      media_content_type: music
entity: media_player.stue_ac

Thank you.
But in addition, I also had to add:

action: call-service

So, now it finally works :wink: