static gboolean
ol_player_xmms2_stop ()
{
  ol_log_func ();
  if (!ol_player_xmms2_ensure_connection ())
    return FALSE;
  xmmsc_result_unref (xmmsc_playback_stop (connection));
  return TRUE;
}
Exemple #2
0
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;

}