void mpdclient_init() { if (!mpdclient_connect()) { mpdclient_playlist_update(NULL); ecore_timer_add(1.0, mpdclient_playlist_update, NULL); //music_playlist_scroll(0, 1, 1); } //mpd_closeConnection(conn); put this somewhere }
/** * This timer is installed when the connection to the MPD server is * broken. It tries to recover by reconnecting periodically. */ static gboolean timer_reconnect(G_GNUC_UNUSED gpointer data) { bool success; struct mpd_connection *connection; assert(!mpdclient_is_connected(mpd)); reconnect_source_id = 0; char *name = default_settings_name(); screen_status_printf(_("Connecting to %s... [Press %s to abort]"), name, get_key_names(CMD_QUIT, false)); g_free(name); doupdate(); mpdclient_disconnect(mpd); success = mpdclient_connect(mpd, options.host, options.port, options.timeout_ms, options.password); if (!success) { /* try again in 5 seconds */ reconnect_source_id = g_timeout_add(5000, timer_reconnect, NULL); return FALSE; } connection = mpdclient_get_connection(mpd); #ifndef NCMPC_MINI /* quit if mpd is pre 0.11.0 - song id not supported by mpd */ if (mpd_connection_cmp_server_version(connection, 0, 12, 0) < 0) { const unsigned *version = mpd_connection_get_server_version(connection); screen_status_printf(_("Error: MPD version %d.%d.%d is to old (%s needed)"), version[0], version[1], version[2], "0.12.0"); mpdclient_disconnect(mpd); doupdate(); /* try again after 30 seconds */ reconnect_source_id = g_timeout_add(30000, timer_reconnect, NULL); return FALSE; } #endif if (mpd_connection_cmp_server_version(connection, 0, 14, 0) >= 0) mpd->source = mpd_glib_new(connection, idle_callback, mpd); name = connection_settings_name(connection); screen_status_printf(_("Connected to %s"), name); g_free(name); doupdate(); /* update immediately */ mpd->events = MPD_IDLE_ALL; do_mpd_update(); auto_update_timer(); return FALSE; }