node-red-contrib-play-sound
Version:
Node-RED node for play-sound (based on nodejs play-sound : Play sounds by shelling out to one of the available audio players).
95 lines (92 loc) • 3.38 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('PlaySound',{
category: 'output',
color: '#daaff7',
icon: "unmute.png",
label: function() {
return this.name || "PlaySound";
},
defaults: {
name: {value:""},
playerOptions: {value:"", validate: function(v) {
try {
JSON.parse(v);
return true;
} catch(err) {
return false;
}
}},
audioURI: {value:""},
options: {value:"", validate: function(v) {
try {
JSON.parse(v);
return true;
} catch(err) {
return false;
}
}},
},
inputs:1,
outputs:1,
button: {
onclick: function() {
var label = this.name||"PlaySound";
var node = this;
$.ajax({
url: "PlaySound/"+this.id,
type: "POST",
success: function(resp, textStatus, xhr) {
RED.notify(node._("inject.success",{label:label}),"success");
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.not-deployed")}),"error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error",{message:node._("inject.errors.failed")}),"error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.no-response")}),"error");
} else {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.unexpected",{status:jqXHR.status,message:textStatus})}),"error");
}
}
});
}
}
});
</script>
<script type="text/x-red" data-template-name="PlaySound">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> name</label>
<input type="text" id="node-input-name" placeholder="name">
</div>
<div class="form-row">
<label for="node-input-playerOptions"><i class="icon-tag"></i> Player options</label>
<input type="text" id="node-input-playerOptions" placeholder="{} or {player:"--see play-sound npm package--"}">
</div>
<div class="form-row">
<label for="node-input-audioURI"><i class="icon-tag"></i> Audio URI</label>
<input type="text" id="node-input-audioURI" placeholder="File name or url">
</div>
<div class="form-row">
<label for="node-input-options"><i class="icon-tag"></i> Audio Options</label>
<input type="text" id="node-input-options" placeholder="{} or {--see play-sound npm package--}">
</div>
</script>
<script type="text/x-red" data-help-name="PlaySound">
<p><h2>PlaySound</h2></p>
<p>This node play an audio file or url. Could play many sound in the same time.</p>
<p><u>Input</u></p>
<ul>
<li><code>msg.payload</code>: start (or empty) - Start playing</li>
<li><code>msg.payload</code>: stop - Stop all sound playing</li>
<li><code>msg.payload</code>: pause - Pause all sound playing</li>
<li><code>msg.payload</code>: resume - Resume all sound playing</li>
<li><code>msg.audioURI</code>: File name or url to play - If empty, then the one in dialog is used</li>
<li><code>msg.options</code>: Audio options - If empty, then the one in dialog is used</li>
</ul>
<p><u>Output</u></p>
<ul>
<li><code>msg.payload</code>: end - Emit at the end of playing sound</li>
<li><code>msg.payload</code>: stop - Emit while playing and a `stop` input is received</li>
</ul>
</script>