void playback_play (cli_infos_t *infos) { xmmsc_result_t *res; res = xmmsc_playback_start (infos->sync); xmmsc_result_wait (res); done (res, infos); }
static gboolean ol_player_xmms2_play () { ol_log_func (); if (!ol_player_xmms2_ensure_connection ()) return FALSE; xmmsc_result_unref (xmmsc_playback_start (connection)); return TRUE; }
int main (int argc, char **argv) { /* * To connect to xmms2d you need to first have a * connection. */ xmmsc_connection_t *connection; /* * xmmsc_result_t is the struct returned from all * commands that are given to the xmms2d server * we just declare a variable of this type here, * we'll need it later. */ xmmsc_result_t *result; /* * xmmsv_t is the wrapper struct used to communicate * values to/from the server. Typically, when a client * issues commands, the server answers by sending back * the return value for the command. Here, we will only * use it to check if the server returned an error. */ xmmsv_t *return_value; /* * We need a string pointer to retrieve the error (if any) * from the xmmsv_t. Note that the string will still be * owned by the xmmsv_t structure. */ const char *err_buf; /* * First we need to initialize the connection; * as argument you need to pass "name" of your * client. The name has to be in the range [a-zA-Z0-9] * because xmms is deriving configuration values * from this name. */ connection = xmmsc_init ("tutorial1"); /* * xmmsc_init will return NULL if memory is * not available */ if (!connection) { fprintf (stderr, "OOM!\n"); exit (EXIT_FAILURE); } /* * Now we need to connect to xmms2d. We need to * pass the XMMS ipc-path to the connect call. * If passed NULL, it will default to * unix:///tmp/xmms-ipc-<user>, but all xmms2 clients * should handle the XMMS_PATH enviroment in * order to configure connection path. * * xmmsc_connect will return NULL if an error occured * and it will set the xmmsc_get_last_error() to a * string describing the error */ if (!xmmsc_connect (connection, getenv ("XMMS_PATH"))) { fprintf (stderr, "Connection failed: %s\n", xmmsc_get_last_error (connection)); exit (EXIT_FAILURE); } /* * This is all you have to do to connect to xmms2d. * Now we can send commands. Let's do something easy * like getting xmms2d to start playback. */ result = xmmsc_playback_start (connection); /* * The command will be sent, and since this is a * synchronous connection we can block for its * return here. The async / sync issue will be * commented on later. */ xmmsc_result_wait (result); /* * When xmmsc_result_wait() returns, we have the * answer from the server. We now extract that value * from the result. Note that the value is still owned * by the result, and will be freed along with it. */ return_value = xmmsc_result_get_value (result); /* * Let's check if the value returned by the server * is an error, and print it out if it is. */ if (xmmsv_is_error (return_value) && xmmsv_get_error (return_value, &err_buf)) { fprintf (stderr, "playback start returned error, %s", err_buf); } /* * This is very important - when we are done with the * result we need to tell that to the clientlib, * we do that by unrefing it. this will free resources, * including the return_value, and make sure that we don't * leak memory. It is not possible to touch the result or * the return_value after we have done this. */ xmmsc_result_unref (result); /* * Now we are done, let's disconnect and free up all * used resources. */ xmmsc_unref (connection); return (EXIT_SUCCESS); }
int main (int argc, char **argv) { /* The mainloop we should use later */ GMainLoop *ml; /* * The first part of this program is * commented on in tut1.c */ xmmsc_connection_t *connection; xmmsc_result_t *result; /* * In an async client we still connect as * normal. Read up on this in earlier * tutorials if you need. */ connection = xmmsc_init ("tutorial6"); if (!connection) { fprintf (stderr, "OOM!\n"); exit (EXIT_FAILURE); } if (!xmmsc_connect (connection, getenv ("XMMS_PATH"))) { fprintf (stderr, "Connection failed: %s\n", xmmsc_get_last_error (connection)); exit (EXIT_FAILURE); } /* * Initialize the mainloop, for more information about GLib mainloop * see the GTK docs. */ ml = g_main_loop_new (NULL, FALSE); /* * We issue two async commands to restart playback. * Since we don't want to set a notifier for those, * we can free the result immediately. */ xmmsc_result_unref (xmmsc_playback_stop (connection)); xmmsc_result_unref (xmmsc_playback_start (connection)); printf ("Playtime: \n"); result = xmmsc_signal_playback_playtime (connection); xmmsc_result_notifier_set (result, my_playtime, ml); xmmsc_result_unref (result); /* * As you see we do it pretty much the same way that we did in tut2, but * instead of being able to access the current id directly (as we would * have if we where blocking) we need to wait until xmms calls our * my_current_id function. This will keep your GUI from hanging while * waiting for xmms2 to answer your command. * * In order to make xmmsclient call your callback functions we need to put * the fd of the connection into the mainloop of our program. For your * convenience the xmmsclient lib ships with automatic integration with * GMainLoop. We just need to link with xmmsclient-glib and do the following * call to make it work. */ xmmsc_mainloop_gmain_init (connection); /* * We are now all set to go. Just run the main loop and watch the magic. */ g_main_loop_run (ml); return EXIT_SUCCESS; }