# Omxplayer need help to play sounds on raspi

**URL:** https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643
**Category:** General
**Created:** [17 September 2019 21:05 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643 "2019-09-17T21:05:33Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [17 September 2019 21:05 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/1 "2019-09-17T21:05:33Z")

</div>

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

> **[node-red-contrib-pi-omxplayer](https://flows.nodered.org/node/node-red-contrib-pi-omxplayer)**
>
> A Node-RED node to control OMXPlayer on the Raspberry pi

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

```auto
[
    {
        "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": [
            [
                "1b7e103f.15fa38"
            ]
        ]
    },
    {
        "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": [
            [
                "92596eed.3f2998"
            ]
        ]
    }
]

```

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 September 2019 21:20 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/2 "2019-09-17T21:20:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [17 September 2019 21:37 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/3 "2019-09-17T21:37:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [17 September 2019 21:45 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/4 "2019-09-17T21:45:04Z")

</div>

I removed it but didn´t work even so

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

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [17 September 2019 21:59 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/5 "2019-09-17T21:59:41Z")

</div>

Set it to object mode, then inject a preconfigured object as message  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 10:18 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/6 "2019-09-18T10:18:00Z")

</div>

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:  
[picture](http://puu.sh/EizdG/ade8723ed1.png)  
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!

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [18 September 2019 10:31 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/7 "2019-09-18T10:31:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 September 2019 10:48 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/8 "2019-09-18T10:48:57Z")

</div>

> [@afelix](#):
>
> the option JSON means you're setting a JavaScript object. Tap the button on the right and set it to

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.

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 10:53 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/9 "2019-09-18T10:53:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [18 September 2019 11:06 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/10 "2019-09-18T11:06:08Z")

</div>

Thanks Nick, that slipped my mind for a moment.

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [18 September 2019 11:12 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/11 "2019-09-18T11:12:19Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 13:06 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/12 "2019-09-18T13:06:25Z")

</div>

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.

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

```

the documentation is \*\*\*\*\* ☹

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 ^^ ☹

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [18 September 2019 13:49 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/13 "2019-09-18T13:49:07Z")

</div>

The documentation is fine.

You should return both the filename and the command.

```auto
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).

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 14:25 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/14 "2019-09-18T14:25:51Z")

</div>

> [@bakman2](#):
>
> filename = "/home/pi/Desktop/lassedenken.mp3" return {filename:filename,payload:"playpause"}

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 ?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 September 2019 14:28 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/15 "2019-09-18T14:28:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 14:43 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/16 "2019-09-18T14:43:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [18 September 2019 14:43 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/17 "2019-09-18T14:43:53Z")

</div>

Enter  
`which omxplayer`

Use the full path in the exec node.

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [18 September 2019 14:48 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/18 "2019-09-18T14:48:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![WhiteLion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/whitelion/32/12266_2.png) [@WhiteLion](https://discourse.nodered.org/u/WhiteLion)
#### Post date: [18 September 2019 14:49 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/19 "2019-09-18T14:49:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [18 September 2019 14:59 UTC](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643/20 "2019-09-18T14:59:17Z")

</div>

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

[Next page](https://discourse.nodered.org/t/omxplayer-need-help-to-play-sounds-on-raspi/15643.md?page=2)
