Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:14:20+00:00 2026-06-18T05:14:20+00:00

I am trying to write a module for nodeJS which wraps libspotify. The goal

  • 0

I am trying to write a module for nodeJS which wraps libspotify. The goal is to write a webapp that allows the remote control of a device playing music from spotify.

I have decided to go along the spshell example to ensure thread safety and write a “Spotify Service” in plain C that starts a seperate thread which calls all the API functions.

The nodeJS module then just calls a few provided functions to interact with spotify. The code for the service can be found here: http://pastebin.com/KB6uwSC8 The new thread gets started at the bottom.

Now, if i call this in a simple program like this (the fget is just to have a simple way for the login to complete). I used c++ to get as close to as node-gyp compiles the code.

#include <stdio.h>

extern "C" {
        #include "objects/SpotifyService.h"
}

int  main(int argc, char** argv) {
    login();
    char string[100];
    fgets(string, 100, stdin);
    fprintf(stdout, "Got: %s", string);
    logout();
    fgets(string, 100, stdin);
    fprintf(stdout, "Got: %s", string);
    return 0;
}

It works fine. I can’t get this to crash.

If I use the same exact “Service” in nodeJS (meaning I just call login() and logout() and do nothing else), it crashes sometimes when logging out, like 7-8/10 times. I’ve tried lots of stuff, including:

  • Copying the compiler flags from node-gyp to my small example
  • fiddling with the thread attributes of the spotify thread
  • compiling on OSX and Debian
  • using libuv instead of plain pthreads
  • compiling my “service” to a shared library and call this from node

to no avail. It just crashes. It seems to crash less when called from within gdb, but that could be random.

A stack trace from gdb shows the following:

Thread 3 (Thread 0x7ffff65fd700 (LWP 21838)):
#0  0x00007ffff678f746 in ?? () from /usr/local/lib/libspotify.so.12
#1  0x00007ffff6702289 in ?? () from /usr/local/lib/libspotify.so.12
#2  0x00007ffff6702535 in ?? () from /usr/local/lib/libspotify.so.12
#3  0x00007ffff6703b5a in ?? () from /usr/local/lib/libspotify.so.12
#4  0x00007ffff6703c86 in ?? () from /usr/local/lib/libspotify.so.12
#5  0x00007ffff66c5c8b in ?? () from /usr/local/lib/libspotify.so.12
#6  0x00007ffff679a5b3 in sp_session_process_events () from /usr/local/lib/libspotify.so.12
#7  0x00007ffff6aa7839 in spotifyLoop (nervNicht=<value optimized out>) at    ../src/SpotifyService.c:103
#8  0x00007ffff70118ca in start_thread () from /lib/libpthread.so.0
#9  0x00007ffff6d78b6d in clone () from /lib/libc.so.6
#10 0x0000000000000000 in ?? ()

(In OSX gdb showed that the function called in libspotify is called “process_title”.)

Since nothing has helped so far i just don’t have any idea if i can get this to work or if it is something in libspotify that’s just incompatible with nodeJS. I don’t understand how node-gyp links the .o files, maybe there something goes wrong?

I found two other projects on github that try to do this, but one of them puts the spotify main loop actually in Javascript and the other one uses node 0.1.100 and libspotify 0.0.4 and hasn’t been updated in 2 years. I couldn’t learn anything from both of them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:14:21+00:00Added an answer on June 18, 2026 at 5:14 am

    OK, i’ve played around some more. I just ignored the logout error and continued to implement other features.

    I added a new sp_playlist_container creation in the logged_in callback and apparently that helped. After that, the node module does not crash anymore (or hasn’t yet).

    static sp_playlistcontainer_callbacks pc_callbacks = {
         .container_loaded = &rootPlaylistContainerLoaded,
    };
    
    static void rootPlaylistContainerLoaded(sp_playlistcontainer* pc, void* userdata) {
        int numPlaylists = sp_playlistcontainer_num_playlists(pc);
        fprintf(stdout, "Root playlist synchronized, number of Playlists: %d\n", numPlaylists);
    }
    
    static void loggedIn(sp_session* session, sp_error error) {
        if(SP_ERROR_OK != error) {
                fprintf(stderr, "Error logging in: %s\n", sp_error_message(error));
        } else {
                fprintf(stdout, "Service is logged in!\n");
        } 
    
        //This is absolutely necessary here, otherwise following callbacks can crash.
        sp_playlistcontainer *pc = sp_session_playlistcontainer(spotifySession);
        sp_playlistcontainer_add_callbacks(pc, &pc_callbacks, NULL);
    }  
    

    But the sp_playlist_container creation must be in the logged_in callback, if i called it in another function (say, “getPlaylistNames”) the program crashed, too.

    I’ll see if it continues to work and hope this answer can help others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a Node.js module, using C++, that wraps and exposes some
I am trying to write a MSBuild logger module which logs information when receiving
I am trying to write a small app that uses the subprocess module. My
I am trying to write a module which is similar to ping. The problem
I'm trying to write a simple module that will enable sending SMS. I using
I'm trying to write a simple shopping cart Orchard module that will store items
I am trying to write a pam module that will read password from a
I'm trying to write a module for OpenERP 6.1 that will hide the Send
I'm trying to write a Drupal module that will add UTM coordinate fields to
So I'm trying to write a kernel module that uses the linux/timer.h file. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.