|
Packit Service |
0e3298 |
/*-*- Mode: C; c-basic-offset: 8 -*-*/
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/***
|
|
Packit Service |
0e3298 |
This file is part of libcanberra.
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
Copyright 2008 Lennart Poettering
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
libcanberra is free software; you can redistribute it and/or modify
|
|
Packit Service |
0e3298 |
it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
0e3298 |
published by the Free Software Foundation, either version 2.1 of the
|
|
Packit Service |
0e3298 |
License, or (at your option) any later version.
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
libcanberra is distributed in the hope that it will be useful, but
|
|
Packit Service |
0e3298 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
0e3298 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
0e3298 |
Lesser General Public License for more details.
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
0e3298 |
License along with libcanberra. If not, see
|
|
Packit Service |
0e3298 |
<http://www.gnu.org/licenses/>.
|
|
Packit Service |
0e3298 |
***/
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
0e3298 |
#include <config.h>
|
|
Packit Service |
0e3298 |
#endif
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
#include <unistd.h>
|
|
Packit Service |
0e3298 |
#include <stdlib.h>
|
|
Packit Service |
0e3298 |
#include <locale.h>
|
|
Packit Service |
0e3298 |
#include <stdio.h>
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
#include "canberra.h"
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
static void callback(ca_context *c, uint32_t id, int error, void *userdata) {
|
|
Packit Service |
0e3298 |
fprintf(stderr, "callback called for id %u, error '%s', userdata=%p\n", id, ca_strerror(error), userdata);
|
|
Packit Service |
0e3298 |
}
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
int main(int argc, char *argv[]) {
|
|
Packit Service |
0e3298 |
ca_context *c;
|
|
Packit Service |
0e3298 |
ca_proplist *p;
|
|
Packit Service |
0e3298 |
int ret;
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
setlocale(LC_ALL, "");
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
ret = ca_context_create(&c);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "create: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* Initialize a few meta variables for the following play()
|
|
Packit Service |
0e3298 |
* calls. They stay valid until they are overwritten with
|
|
Packit Service |
0e3298 |
* ca_context_change_props() again. */
|
|
Packit Service |
0e3298 |
ret = ca_context_change_props(c,
|
|
Packit Service |
0e3298 |
CA_PROP_APPLICATION_NAME, "An example",
|
|
Packit Service |
0e3298 |
CA_PROP_APPLICATION_ID, "org.freedesktop.libcanberra.Test",
|
|
Packit Service |
0e3298 |
CA_PROP_WINDOW_X11_SCREEN, getenv("DISPLAY"),
|
|
Packit Service |
0e3298 |
NULL);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "change_props: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
ret = ca_context_open(c);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "open: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* Now trigger a sound event, the quick version */
|
|
Packit Service |
0e3298 |
ret = ca_context_play(c, 0,
|
|
Packit Service |
0e3298 |
CA_PROP_EVENT_ID, "desktop-login",
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/bar.wav",
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_NAME, "User has logged off from session",
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_LANGUAGE, "en_EN",
|
|
Packit Service |
0e3298 |
CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
|
|
Packit Service |
0e3298 |
NULL);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "play: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* Now trigger a sound event, the complex version */
|
|
Packit Service |
0e3298 |
ca_proplist_create(&p);
|
|
Packit Service |
0e3298 |
ca_proplist_sets(p, CA_PROP_EVENT_ID, "desktop-logout");
|
|
Packit Service |
0e3298 |
ca_proplist_sets(p, CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/uxknkurz.wav");
|
|
Packit Service |
0e3298 |
ca_proplist_sets(p, CA_PROP_MEDIA_NAME, "New email received");
|
|
Packit Service |
0e3298 |
ca_proplist_setf(p, "test.foo", "%u", 4711);
|
|
Packit Service |
0e3298 |
ret = ca_context_play_full(c, 1, p, callback, (void*) 0x4711);
|
|
Packit Service |
0e3298 |
ca_proplist_destroy(p);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "play_full: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* Now trigger a sound event, by filename */
|
|
Packit Service |
0e3298 |
ret = ca_context_play(c, 2,
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_FILENAME, "/usr/share/sounds/freedesktop/stereo/audio-channel-front-left.ogg",
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_NAME, "Front Left",
|
|
Packit Service |
0e3298 |
CA_PROP_MEDIA_LANGUAGE, "en_EN",
|
|
Packit Service |
0e3298 |
NULL);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "play (by filename): %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
fprintf(stderr, "Sleep half a second ...\n");
|
|
Packit Service |
0e3298 |
usleep(500000);
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* Stop one sound */
|
|
Packit Service |
0e3298 |
/* ret = ca_context_cancel(c, 0); */
|
|
Packit Service |
0e3298 |
/* fprintf(stderr, "cancel: %s\n", ca_strerror(ret)); */
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
fprintf(stderr, "Sleep 2s ...\n");
|
|
Packit Service |
0e3298 |
sleep(2);
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
/* .. */
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
ret = ca_context_destroy(c);
|
|
Packit Service |
0e3298 |
fprintf(stderr, "destroy: %s\n", ca_strerror(ret));
|
|
Packit Service |
0e3298 |
|
|
Packit Service |
0e3298 |
return 0;
|
|
Packit Service |
0e3298 |
}
|