Skip to content
Advertisement

Deezer native API under linux: Unanble to create simple app

I tried to create simple app which will connect to deezer and play single song. I got access token and wrote this program.
Target machine: linux x86_64
API version: v1.0.1

#include <iostream>
#include <deezer-api.h>
#include <deezer-player.h>

#define ACCESS_TOKEN "ACCESS TOKEN HERE"

int main(int argc, char **argv)
{
    dz_connect_configuration cfg = {0};
    cfg.app_id = "APP ID HERE";
    cfg.product_id = "product_id";
    cfg.product_build_id = "0.0.0";

    dz_connect_handle dz_handle = dz_connect_new(&cfg);
    if (dz_handle == nullptr)
    {
        return 100;
    }

    auto err_code = dz_connect_activate(dz_handle, nullptr);
    if (err_code > DZ_ERROR_NO_ERROR_ASYNC)
    {
        return err_code;
    }

    err_code = dz_connect_set_access_token(dz_handle, nullptr, nullptr, ACCESS_TOKEN);
    if (err_code > DZ_ERROR_NO_ERROR_ASYNC)
    {
        return err_code;
    }

    auto dz_player_handle = dz_player_new(dz_handle);
    if (dz_player_handle == nullptr)
    {
        return 200;
    }

    err_code = dz_player_activate(dz_player_handle, nullptr);
    if (err_code > DZ_ERROR_NO_ERROR_ASYNC)
    {
        return err_code;
    }

    err_code = dz_player_load(dz_player_handle, nullptr, nullptr, "dzmedia:///track/3135556");
    if (err_code > DZ_ERROR_NO_ERROR_ASYNC)
    {
        return err_code;
    }

    err_code = dz_player_play(dz_player_handle, nullptr, nullptr, DZ_PLAYER_PLAY_CMD_START_TRACKLIST, DZ_TRACKLIST_AUTOPLAY_MANUAL, DZ_INDEX_IN_PLAYLIST_CURRENT);
    if (err_code > DZ_ERROR_NO_ERROR_ASYNC)
    {
        return err_code;
    }
    std::cin.get();
    return 0;
}

Suddenly i ran into problems. First run shows me this output:

398748:201417 dz_bufferevent: [dz_bufferevent_on_activation:561] could not open /var/tmp/settings.dat

I created this file, but I suspect that it shouldn’t be empty. After second run with /var/tmp/settings.dat created i got this output:

399206:328658 dz_crash_handler: [dz_crash_handler_init:284] Crash Handler available
399206:329404 dzcrashreport-server-disk: [dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
399206:329533 dzcrashreport-server-disk: [dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
399206:329590 dzcrashreport-server-disk: [dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
399206:329664 dzcrashreport-server-disk: [dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
399206:329726 dzcrashreport-server-disk: [dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
399206:329736 dzcrashreport-sender: [dz_crash_report_sender_retrieve_server_url_on_result:213] Error – couldn’t read URL server err:0
399206:336505 pulseaudio-engine: [dz_audioengine_set_output_gain:1184] not init
399206:336520 pulseaudio-engine: [dz_audioengine_set_output_gain:1184] not init
399206:336577 player: [dz_player_play_licence:1756] unknown error 131079

I can’t understand, what i did wrong?

UPDATE:
Deezer Native API: v1.0.1-v00349200

Still no luck. Tried different variations of "user_profile_path":

  • .
  • ./
  • ./user – was created in working dir with 777 rights
  • /var/tmp

There were no files in the folder created by API.

Still got errors:

[dz_crashreport_server_url_on_read_data:436] ERROR – Open failure err: 7
[dz_crash_report_sender_retrieve_server_url_on_result:213] Error – couldn’t read URL server err:0

After adding implementation of callbacks i see this:

  1. dz_connect_set_access_token calls callback dz_activity_operation_callback with status DZ_ERROR_CONNECT_SESSION_OFFLINE_MODE
  2. dz_player_play calls callback dz_player_onevent_cb with event DZ_PLAYER_EVENT_PLAYLIST_TRACK_NO_RIGHT

Well, i checked that i have rights to play this track.

Advertisement

Answer

the "could not open" message is just informative. The file will be automatically created (or updated if detected corrupted). The issue seems more linked to the dz_connect_configuration, you have to set the "user_profile_path" to a valid path. This is where user temporary files will be stored. Regards, Cyril

UPDATE:

Few tips that could also help:

  • My mistake, one call seems missing: dz_connect_cache_path_set(dz_handle, NULL, NULL, <user_profile_path>);

  • The DZ_INDEX_IN_PLAYLIST_CURRENT must be replaced by 0. I do agree this one is not obvious…

  • Check that the access_token you have created has the offline_access enable when calling https://connect.deezer.com/oauth/auth.php?app_id=YOUR_APP_ID&redirect_uri=YOUR_REDIRECT_URI&perms=basic_access,email,offline_access (cf: http://developers.deezer.com/api/oauth and http://developers.deezer.com/api/permissions)

UPDATE 2: Since my last answer I have released a sample code on Github: https://github.com/deezer/native-sdk-samples

I suggest that you have a quick look 🙂

What I have noticed in your full code you sent me in private is that:

  • You are not calling dz_connect_offline_mode(...,false); It will actually trigger the login process of the Native SDK.

  • You are not waiting the DZ_CONNECT_EVENT_USER_LOGIN_OK to load and play the track.

Best regards,

Cyril

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement