# Audio file playback and stopping playback

**URL:** <https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692>\
**Category:** General\
**Created:** [7 March 2019 08:17 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692 "2019-03-07T08:17:21Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 08:17 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/1 "2019-03-07T08:17:21Z")

</div>

Hello all,

I am very new to Node-red. So I am hoping I am just missing something obvious.

I have a Raspberry Pi3 running Node-red 0.19.6, node.js 10.15.1

I am trying to play a local sound file (.Wav) on the mini-jack output.  
This works as expected by using the "Play\_sound" node into a "Play\_audio" node.  
What is not working is stopping the Audio file.  
in the description of the node it says to send "msg.payload ; stop"  
I have tried all variations of this that I can think off, but I cant get it to work.  
it always plays out to the end of the file.  
is there any way of doing this?

all help is appreciated.

---

<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:** [7 March 2019 08:51 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/2 "2019-03-07T08:51:37Z")

</div>

Put a debug node showing what you are sending to stop it and paste the result here.  
Also please confirm which node you are using to play it. Is it a node-red-contrib-something node?

---

<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:** [7 March 2019 08:52 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/3 "2019-03-07T08:52:48Z")

</div>

Just to check, you are not setting msg.payload to "msg.payload: stop" are you? I imagine it means that you should set msg.payload to "stop".

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 09:04 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/4 "2019-03-07T09:04:22Z")

</div>

Hi Colin,

thanks for responding;  
I am using  
node-red-contrib-play-sound

I am sending a msg.payload string "stop"  
I pasted the debug output.

pi/15 : msg.payload : string[4]

"stop"

I have also tried to use a change node and make the msg.stop this has no effect...

thanks for your help.

Sander

---

<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:** [7 March 2019 09:08 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/5 "2019-03-07T09:08:00Z")

</div>

Can you make a test flow consisting of the play node and some inject nodes to start/stop it so we can try it ourselves? Post that here.

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 09:13 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/6 "2019-03-07T09:13:39Z")

</div>

Hi Colin,

I have not done this before, so I hope this works.  
The sound file that is referenced in the flow is local on my pi.  
It would have to be replaced with something on your end.

Thanks

Sander

[{"id":"a992881b.240248","type":"tab","label":"send to forum","disabled":false,"info":""},{"id":"1226b862.a3c8a8","type":"PlaySound","z":"a992881b.240248","name":"hello","playerOptions":"{}","audioURI":"/home/pi/Music/Hello.wav","options":"{}","x":550,"y":281,"wires":[["7051e885.492bf8","ff1b253a.d96ec8"]]},{"id":"7051e885.492bf8","type":"play audio","z":"a992881b.240248","name":"","voice":"0","x":901,"y":273,"wires":[]},{"id":"ff1b253a.d96ec8","type":"debug","z":"a992881b.240248","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":899.5,"y":315,"wires":[]},{"id":"56121db3.5b1d04","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"play","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.5,"y":245,"wires":[["1226b862.a3c8a8"]]},{"id":"e2fbba98.02b158","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":183.5,"y":312,"wires":[["1226b862.a3c8a8"]]}]

---

<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:** [7 March 2019 09:20 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/7 "2019-03-07T09:20:04Z")

</div>

Please see this on how to share a flow. You can go back and edit the previous message.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 09:25 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/8 "2019-03-07T09:25:05Z")

</div>

Thanks,  
here it is  
Sander

```auto
[{"id":"1226b862.a3c8a8","type":"PlaySound","z":"a992881b.240248","name":"hello","playerOptions":"{}","audioURI":"/home/pi/Music/Hello.wav","options":"{}","x":550,"y":281,"wires":[["7051e885.492bf8","ff1b253a.d96ec8"]]},{"id":"7051e885.492bf8","type":"play audio","z":"a992881b.240248","name":"","voice":"0","x":901,"y":273,"wires":[]},{"id":"ff1b253a.d96ec8","type":"debug","z":"a992881b.240248","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":899.5,"y":315,"wires":[]},{"id":"56121db3.5b1d04","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"play","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.5,"y":245,"wires":[["1226b862.a3c8a8"]]},{"id":"e2fbba98.02b158","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"pause","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":163.5,"y":312,"wires":[["1226b862.a3c8a8"]]}]

```

---

<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:** [7 March 2019 09:36 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/9 "2019-03-07T09:36:23Z")

</div>

You have another node there that you have not said what it is. The play audio node. But I don't understand why you need both.

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 09:40 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/10 "2019-03-07T09:40:47Z")

</div>

aha, you are right.  
that only plays the audio in the browser.  
I just tried to take that our and it still works.  
but the "stop" still has no effect.

it is this now

```auto
[{"id":"1226b862.a3c8a8","type":"PlaySound","z":"a992881b.240248","name":"hello","playerOptions":"{}","audioURI":"/home/pi/Music/Hello.wav","options":"{}","x":562,"y":284,"wires":[["ff1b253a.d96ec8"]]},{"id":"ff1b253a.d96ec8","type":"debug","z":"a992881b.240248","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":903.5,"y":294,"wires":[]},{"id":"56121db3.5b1d04","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"play","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.5,"y":245,"wires":[["1226b862.a3c8a8"]]},{"id":"e2fbba98.02b158","type":"inject","z":"a992881b.240248","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.5,"y":311,"wires":[["1226b862.a3c8a8"]]}]

```

---

<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:** [7 March 2019 10:00 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/11 "2019-03-07T10:00:34Z")

</div>

Well unfortunately I can't make it go at all (on Ubuntu) , so difficult for me to test. However there is this issue on the node which might be relevant.

> <https://github.com/MattVador/node-red-contrib-play-sound/issues/3>

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 10:02 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/12 "2019-03-07T10:02:44Z")

</div>

Hi Colin,

that is indeed relevant...

Do you know of any other Nodes that would play a sound file (and are stoppable?)

thanks  
for your help

Sander

---

<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:** [7 March 2019 10:11 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/13 "2019-03-07T10:11:52Z")

</div>

> [@sanderl](#):
>
> Do you know of any other Nodes that would play a sound file (and are stoppable?)

I don't, sorry. Someone else may. I don't know why that issue was closed, it appears to be a bug in the node.

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 10:12 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/14 "2019-03-07T10:12:49Z")

</div>

I think I will report it again. maybe it can be fixed.

thanks a lot for your help

Sander

---

<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:** [7 March 2019 10:20 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/15 "2019-03-07T10:20:57Z")

</div>

You said in your first post you were using the Jack output, the issue says it is ok on the jack, but not on the hdmi.  
Also I notice the node does not even produce an error if it can't find the file, which seems odd.

---

<div class="post-metadata">

**Author:** ![sanderl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanderl/32/6205_2.png) [@sanderl](https://discourse.nodered.org/u/sanderl)\
**Post date:** [7 March 2019 11:16 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/16 "2019-03-07T11:16:03Z")

</div>

Indeed.

I also have now forced the raspi-config to the jack output. No difference.

Trying to figure out if I can set the volume to zero or something else.

Thanks for your help

---

<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:** [7 March 2019 11:27 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/17 "2019-03-07T11:27:30Z")

</div>

Also worth reopening / opening a new issue, so that the author knows it is still a problem

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [5 October 2021 10:57 UTC](https://discourse.nodered.org/t/audio-file-playback-and-stopping-playback/8692/19 "2021-10-05T10:57:41Z")

</div>


