-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Hey folks.
Great Library you're working on!
When i play one song after another (...and so on) the quality gets worse.
It could be a desync between the L and R channel or something else.
it doesnt matter if i use the node-speaker or aplay player. so it looks like its the audio stream from spotify.
the code:
sidenote: i added Player.isPlaying attribute. this is just the spotify.js file. it wont run.
module.exports = function()
{
var libspotify = require('libspotify');
var config = require('../config.json');
var Speaker = require('speaker');
var audioOptions = {channels: 2, bitDepth: 16, sampleRate: 44100};
var self = this;
this.currentList = null;
this.maxTrackCount = config.maxTrackCount || 12;
this.search = function(data, callback)
{
console.log('spotify search');
if(!self.session)
{
self.createSession();
}
var search = new libspotify.Search(data);
search.trackCount = self.maxTrackCount;
search.execute();
search.once('ready', function() {
if(!search.tracks.length) {
console.error('there is no track to play :[');
callback({error: 'there is no track to play :['});
}
else
{
self.currentList = search.tracks;
callback(search.tracks);
//console.log(search.tracks);
}
});
};
this.startPlayer = function(data, callback)
{
if( self.player && self.player.isPlaying )
{
self.player.stop();
}
if(self.session)
{
var track = self.currentList[data];
self.player = self.session.getPlayer();
self.player.load(track);
self.player.play();
self.player.pipe(new Speaker( audioOptions ));
console.error('playing track. end in %s', track.humanDuration);
self.player.once('track-end', function() {
console.error('track ended');
if(typeof callback === "function")
{
callback();
}
self.player.stop();
session.close();
});
}
else
{
return false;
}
};
this.stopPlayer = function()
{
console.log('stop Player');
if(self.player)
{
self.player.stop();
}
};
this.createSession = function()
{
console.log('spotify create Session');
self.session = new libspotify.Session({
applicationKey: __dirname + '/../spotify_appkey.key'
});
self.session.login(config.credentials.login, config.credentials.password);
return self;
};
return {
search: search,
stopPlayer : stopPlayer,
startPlayer : startPlayer
};
};Metadata
Metadata
Assignees
Labels
No labels