Open antonbrams opened 8 years ago
Second this.
Ok after looking at the lib/rtspmethods.js file, I noticed that the volume had a onVolumeChange listener. With knowledge of that I created this:
'use strict';
var AirTunesServer = require('nodetunes');
var Speaker = require('speaker');
var Volume = require('pcm-volume');
var speaker = new Speaker({
channels: 2,
bitDepth: 16,
sampleRate: 44100,
});
var volume = new Volume();
var server = new AirTunesServer({ serverName: 'Test Speaker' });
server.on('clientConnected', function(stream) {
volume.pipe(speaker);
stream.pipe(volume);
});
server.on('volumeChange', function(e) {
if(e == -144) { // muted
volume.setVolume(0);
} else { // set volume
var newVolume = (e - -30) * (1 - 0) / (0 - -30) + 0;
volume.setVolume(newVolume);
}
});
server.start();
All you need to do is copy and paste that code, also install the dependency npm install pcm-volume
, you may want to add --save
to the end when building program.
@jbonnett92 It's worked to change the volume, but when I disconnect and reconnect it, the sound is distorted, do you know what is causing this? I have tested with my computer and raspberry, both presented this issue.
@rafaelncarvalho Try this:
'use strict';
var AirTunesServer = require('nodetunes');
var Speaker = require('speaker');
var Volume = require('pcm-volume');
var speaker = new Speaker({
channels: 2,
bitDepth: 16,
sampleRate: 44100,
});
var volume = new Volume();
volume.pipe(speaker);
var server = new AirTunesServer({ serverName: 'Test Speaker' });
server.on('clientConnected', function(stream) {
stream.pipe(volume);
});
server.on('volumeChange', function(e) {
if(e == -144) { // muted
volume.setVolume(0);
} else { // set volume
var newVolume = (e - -30) * (1 - 0) / (0 - -30) + 0;
volume.setVolume(newVolume);
}
});
server.start();
Let me know if it does or doesn't work.
@jbonnett92 It works perfectly! Thank you very much!
is it an issue? p.s. and when do you will update the version with fixed "server.stop()"?