Omxplayer need help to play sounds on raspi

I found the omxplayer node and try to use it without success.

Console cmd "omxplayer -p -o local /home/pi/Desktop/lassedenken.mp3" works.
My flow doesn´t work and is probably (lag of documentation) wrong:

        "id": "92596eed.3f2998",
        "type": "rpi-omxplayer",
        "z": "96d7adea.07818",
        "name": "",
        "filename": "",
        "audiooutput": "local",
        "blackbackground": true,
        "disablekeys": false,
        "disableosd": true,
        "disableghostbox": false,
        "subtitlepath": "",
        "loop": false,
        "x": 710,
        "y": 200,
        "wires": [
        "id": "34d0d257.ac99c6",
        "type": "inject",
        "z": "96d7adea.07818",
        "name": "",
        "topic": "",
        "payload": "playSomeShit!",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 370,
        "y": 200,
        "wires": [
        "id": "1b7e103f.15fa38",
        "type": "function",
        "z": "96d7adea.07818",
        "name": "setAudio",
        "func": "msg.filename = \"~/home/pi/Desktop/lassedenken.mp3\";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 520,
        "y": 200,
        "wires": [

Goal is to play audio on the analog output of my raspi where node-red is running.
Can someone help pls ?

You should not have ~ in front of /home in the filename.

Also for future reference you don’t need that function node you can inject an object with a filename property on it instead.

I removed it but didn´t work even so

I could remove function node if only I know how to set "msg.filename" with only injection node.

Set it to object mode, then inject a preconfigured object as message

I am sorry, I dont get how to set an injection node to an object that can set "msg.filename".
Am I missing someting ? This are the options for my injection node:
I the discription (link) there is a option "msg." which I dont have. - I dont know why.
However I did set the "msg.filename" with javascript, that did set the msg.filename but didnt work in point of the "first post problem" . so I guess setting the same parameter by unsing injection node instaed of the function node will not solve the problem?
Thanx for the fast repleys!

the option JSON means you're setting a JavaScript object. Tap the button on the right and set it to
{ filename: '<your filename here>' }

That will set msg.payload.filename - not what is needed here.

You cannot set msg.filename from an Inject node directly - you could use a Change node after the Inject node to do so.

ok, so what I did at the beginning was right. I used a function node to set msg.filename ....
Hmmmpf, so I am still where I started the thread.

Thanks Nick, that slipped my mind for a moment.

In your flow you are sending msg.payload set to "playSomeShit!"

Taken from the node documentation

A Node-RED node to control OMXPlayer on the Raspberry pi

This node will accept the following commands as msg.payload :

  • open
  • playpause
  • pause
  • stop
  • volumeup
  • volumedown
  • getduration
  • getposition
  • getstatus
  • getvolume
  • setvolume float (0-1)
  • setposition int

I don't see that command there. Have you tried setting msg.payload to one of the commands?

1 Like

I did try "open" and gave an url to a .mp3 .. that didnt work.
Since there is no "play" or "start" I thougth that the song is autoplayed when my fuction node sends a vailid filepath.

msg.filename = "/home/pi/Desktop/lassedenken.mp3";
return msg;

the documentation is ***** :frowning:

Console cmd "omxplayer -p -o local /home/pi/Desktop/lassedenken.mp3" works.

Maybe I could find somehow out how omxplayer node works ? or should I use an exec node and cut together these command line myself ?

EDIT: exce node gave me error 255 when using this command ^^ :frowning:

The documentation is fine.

You should return both the filename and the command.

filename = "/home/pi/Desktop/lassedenken.mp3"
return {filename:filename,payload:"playpause"}

Can't test it though, does the node still work (last update is 2 years ago).

Thx ! I get "Error: not redy yet"... hmmmpf, maybe its outdated or so.
Any idea why exec node "omxplayer -p -o local /home/pi/Desktop/lassedenken.mp3" gives error while e.g. "sudo reboot" works ?

What error?
You may have to provide the full path to omxplayer.

exec node "omxplayer -p -o local /home/pi/Desktop/lassedenken.mp3" gives "error 255" (picture)
I am no linux expert but isn´t this ^^ the full path since "home" dir is located at root ?

which omxplayer

Use the full path in the exec node.

As @bakman2 hinted @colin suggested trying the full path the the executable not the music file

:slight_smile: of course you mean the path to the player... sry :slight_smile:
I have the same error (255) with "usr/bin/omxplayer -p -o local /home/pi/Desktop/lassedenken.mp3"

Can you show us a screenshot of the error? You can paste an image directly into here.