bool Session::connect() { if (!m_session) { sp_session_config config; Logger::printOut("Creating session"); config.api_version = SPOTIFY_API_VERSION; Logger::printOut("API version:"); char* version = new char[20]; Logger::printOut(itoa(SPOTIFY_API_VERSION, version, 10)); //the api is not copying the string so create a new c string CStdString location = Settings::getCachePath(); char * cstr; cstr = new char [location.size()+1]; strcpy (cstr, location.c_str()); config.cache_location = cstr; config.settings_location = cstr; config.tracefile = NULL; config.application_key = g_appkey; config.application_key_size = g_appkey_size; config.user_agent = "spotyXBMC2"; config.device_id = "XBMC htpc"; sp_session_callbacks cb = m_sessionCallbacks.getCallbacks(); config.callbacks = &cb; config.compress_playlists = true; config.dont_save_metadata_for_playlists = false; config.initially_unload_playlists = false; sp_error error = sp_session_create(&config, &m_session); if (SP_ERROR_OK != error) { Logger::printOut("Failed to create session: error:"); Logger::printOut(sp_error_message(error)); m_session = NULL; return false; } //set high bitrate if (Settings::useHighBitrate()) sp_session_preferred_bitrate(m_session, SP_BITRATE_320k); sp_session_set_connection_type(m_session, SP_CONNECTION_TYPE_WIRED); sp_session_set_connection_rules(m_session, SP_CONNECTION_RULE_NETWORK); sp_session_set_volume_normalization(m_session, Settings::useNormalization()); sp_session_login(m_session, Settings::getUserName().c_str(), Settings::getPassword().c_str(), true); m_isEnabled = true; Logger::printOut("Logged in, returning"); return true; } return false; }
void QSpotifySession::setVolumeNormalize(bool normalize) { qDebug() << "QSpotifySession::setVolumeNormalize" << normalize; if(m_volumeNormalize == normalize) return; QSettings s; s.setValue("volumeNormalize", normalize); m_volumeNormalize = normalize; if(sp_session_set_volume_normalization(m_sp_session, normalize) != SP_ERROR_OK) qDebug() << "Failed to set volume normalization"; emit volumeNormalizeChanged(); }