Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

audio quality gets worse when playing song after song after song... #25

Open
moolen opened this issue Sep 14, 2013 · 0 comments
Open

audio quality gets worse when playing song after song after song... #25

moolen opened this issue Sep 14, 2013 · 0 comments

Comments

@moolen
Copy link

moolen commented Sep 14, 2013

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
    };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant