From e9e9444c94641c8a30021fc7aa565cd5a7b70ad6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 3 Jan 2019 10:07:25 +0100 Subject: gtk-play: add quiet option Add an option to suppress the error messages. This is useful in startup scripts when playing sound events for which the theme didn't specify a sound file. --- src/canberra-gtk-play.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/canberra-gtk-play.c b/src/canberra-gtk-play.c index 3e02040..a8347a2 100644 --- a/src/canberra-gtk-play.c +++ b/src/canberra-gtk-play.c @@ -33,6 +33,7 @@ static int ret = 0; static ca_proplist *proplist = NULL; static int n_loops = 1; +static gboolean quiet = FALSE; static void callback(ca_context *c, uint32_t id, int error, void *userdata); @@ -51,7 +52,8 @@ static gboolean idle_play(gpointer userdata) { r = ca_context_play_full(ca_gtk_context_get(), 1, proplist, callback, NULL); if (r < 0) { - g_printerr("Failed to play sound: %s\n", ca_strerror(r)); + if (!quiet) + g_printerr("Failed to play sound: %s\n", ca_strerror(r)); ret = 1; gtk_main_quit(); } @@ -62,7 +64,8 @@ static gboolean idle_play(gpointer userdata) { static void callback(ca_context *c, uint32_t id, int error, void *userdata) { if (error < 0) { - g_printerr("Failed to play sound (callback): %s\n", ca_strerror(error)); + if (!quiet) + g_printerr("Failed to play sound (callback): %s\n", ca_strerror(error)); ret = 1; } else if (n_loops > 1) { @@ -128,6 +131,7 @@ int main (int argc, char *argv[]) { { "loop", 'l', 0, G_OPTION_ARG_INT, &n_loops, "Loop how many times (detault: 1)", "INTEGER" }, { "volume", 'V', 0, G_OPTION_ARG_STRING, &volume, "A floating point dB value for the sample volume (ex: 0.0)", "STRING" }, { "property", 0, 0, G_OPTION_ARG_CALLBACK, (void*) property_callback, "An arbitrary property", "STRING" }, + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Don't print error messages", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; @@ -154,7 +158,8 @@ int main (int argc, char *argv[]) { } if (!event_id && !filename) { - g_printerr("No event id or file specified.\n"); + if (!quiet) + g_printerr("No event id or file specified.\n"); return 1; } @@ -182,7 +187,8 @@ int main (int argc, char *argv[]) { r = ca_context_play_full(ca_gtk_context_get(), 1, proplist, callback, NULL); if (r < 0) { - g_printerr("Failed to play sound: %s\n", ca_strerror(r)); + if (!quiet) + g_printerr("Failed to play sound: %s\n", ca_strerror(r)); ret = 1; goto finish; } -- cgit v1.2.3