music player

You can change "load playlist" node to determine what to play.

This flow require SoX to play sound.

[{"id":"7c803172.0fa5","type":"subflow","name":"singleton play","info":"","in":[{"x":185,"y":362,"wires":[{"id":"752eb1e3.80036"},{"id":"2f732b35.3c90f4"}]}],"out":[{"x":879,"y":384,"wires":[{"id":"4eb8600b.e52fe","port":0}]}]},{"id":"4eb8600b.e52fe","type":"exec","z":"7c803172.0fa5","command":"play","addpay":true,"append":"","useSpawn":"","name":"","x":699,"y":380.5,"wires":[[],[],[]]},{"id":"752eb1e3.80036","type":"exec","z":"7c803172.0fa5","command":"pkill play","addpay":false,"append":"","useSpawn":"","name":"","x":451,"y":264.5,"wires":[[],[],["3079fcd4.c56f84"]]},{"id":"2f732b35.3c90f4","type":"function","z":"7c803172.0fa5","name":"check all","func":"storeMsg(msg);\nvar payloadMsg = allReceived();\nif (payloadMsg) {\n    clear();\n    return payloadMsg;\n}\n\nreturn;\n\nfunction clear() {\n    context.set('pkill', null);\n    context.set('msg', null);\n}\n\nfunction storeMsg(msg) {\n    if (msg._pkill) {\n        context.set('pkill', true);\n    } else {\n        context.set('msg', msg);\n    }\n}\n\nfunction allReceived() {\n    return context.get('pkill') && context.get('msg');\n}","outputs":1,"noerr":0,"x":460,"y":474,"wires":[["4eb8600b.e52fe"]]},{"id":"3079fcd4.c56f84","type":"function","z":"7c803172.0fa5","name":"set pkill","func":"msg._pkill = true;\nreturn msg;","outputs":1,"noerr":0,"x":457,"y":377,"wires":[["2f732b35.3c90f4"]]},{"id":"9f589f1c.9a369","type":"inject","z":"529a97de.ad6568","name":"next","topic":"next","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":101,"y":317,"wires":[["451eea31.d34cc4"]]},{"id":"aa7fb480.50fec8","type":"function","z":"529a97de.ad6568","name":"select file","func":"var playing = msg.playing;\nvar playlist = msg.playlist;\nvar current;\n\nif (msg.topic === 'next') {\n    var current = (playing + 1) % playlist.length;\n}\n\nif (msg.topic === 'shuffle') {\n    var current = parseInt(Math.random() * playlist.length);\n}\n\nmsg.payload = playlist[current];\nmsg.playing = current;\n\nreturn msg;","outputs":1,"noerr":0,"x":1033,"y":372,"wires":[["192b6d05.1b3823","a779389f.ec9d38"]]},{"id":"839330fd.29d62","type":"inject","z":"529a97de.ad6568","name":"shuffle","topic":"shuffle","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":106,"y":454,"wires":[["451eea31.d34cc4"]]},{"id":"924bd0f3.211df","type":"function","z":"529a97de.ad6568","name":"get current index","func":"var playing = flow.get('playing') || 0;\nmsg.playing = playing;\nreturn msg;","outputs":1,"noerr":0,"x":809,"y":371,"wires":[["aa7fb480.50fec8"]]},{"id":"192b6d05.1b3823","type":"function","z":"529a97de.ad6568","name":"set current index","func":"var playlist = msg.playlist;\nflow.set('playing', playlist.indexOf(msg.payload));\nreturn msg;","outputs":1,"noerr":0,"x":1273,"y":373,"wires":[[]]},{"id":"ff1c7a91.fe2aa8","type":"function","z":"529a97de.ad6568","name":"load playlist","func":"msg.playlist = [\n    'playlist/test1.wav',\n    'playlist/test2.wav',\n    'playlist/test3.wav'\n];\n\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":375,"wires":[["924bd0f3.211df"]]},{"id":"8c0126ee.cfde88","type":"inject","z":"529a97de.ad6568","name":"stop","topic":"stop","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":107,"y":590,"wires":[["e6e5f0a9.78424"]]},{"id":"79a66b50.57be04","type":"function","z":"529a97de.ad6568","name":"check auto","func":"var auto = flow.get('auto');\n\nif (auto) {\n    return msg;\n}","outputs":1,"noerr":0,"x":1013,"y":158,"wires":[["924bd0f3.211df"]]},{"id":"59f4e19.e18672","type":"exec","z":"529a97de.ad6568","command":"pkill play","addpay":false,"append":"","useSpawn":"","name":"","x":512,"y":591,"wires":[[],[],[]]},{"id":"e6e5f0a9.78424","type":"function","z":"529a97de.ad6568","name":"set no-auto","func":"flow.set('auto', false);\nreturn msg;","outputs":1,"noerr":0,"x":311,"y":591,"wires":[["59f4e19.e18672"]]},{"id":"451eea31.d34cc4","type":"function","z":"529a97de.ad6568","name":"set auto","func":"flow.set('auto', true);\nreturn msg;","outputs":1,"noerr":0,"x":309,"y":375,"wires":[["ff1c7a91.fe2aa8"]]},{"id":"a779389f.ec9d38","type":"subflow:7c803172.0fa5","z":"529a97de.ad6568","x":778,"y":158,"wires":[["79a66b50.57be04"]]}]
gengen1988

Flow Info

created 1 year, 6 months ago

Node Types

Core
  • exec (x3)
  • function (x9)
  • inject (x3)
Other
  • subflow (x1)
  • subflow:7c803172.0fa5 (x1)

Tags

  • audio
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option