Binary icon data in PNG format for the application this sound event is triggered by. An icon name for the application this sound event is triggered by, as defined in the XDG icon naming specification. An identifier for the program this sound event was triggered by. (e.g. "org.gnu.emacs"). > This attribute will automatically be added to the #GSoundContext with > the #GApplication:application-id if you are using #GApplication, so you > normally do not need to supply this yourself. The locale string the application that is triggering this sound event is running in. A POSIX locale string such as de_DE@euro. The name of the application this sound event was triggered by as human readable string. (e.g. "GNU Emacs") Localized if possible and applicable. > This attribute will automatically be added to the #GSoundContext if > it has previously been set with g_set_application_name(), so you normally > do not need to supply this yourself. The path to the process binary of the process that is triggering this sound event. The host name of the host the process that is triggering this sound event runs on. The unix PID of the process that is triggering this sound event, formatted as string. The user that owns the process that is triggering this sound event. A version number for the program this sound event was triggered by. (e.g. "22.2") A special attribute that can be used to control the automatic sound caching of sounds in the sound server. One of "permanent", "volatile", "never". "permanent" will cause this sample to be cached in the server permanently. This is useful for very frequently used sound events such as those used for input feedback. "volatile" may be used for cacheing sounds in the sound server temporarily. They will expire after some time or on cache pressure. Finally, "never" may be used for sounds that should never be cached, because they are only generated very seldomly or even only once at most (such as desktop login sounds). If this attribute is not explicitly passed to gsound_context_play_simple() or gsound_context_play_full() it will default to "never". If it is not explicitly passed to gsound_context_cache() it will default to "permanent". If the list of attributes is handed on to the sound server this attribute is stripped from it. A special attribute that can be used to control whether any sounds are played at all. If this attribute is "1" or unset sounds are played as normal. However, if it is "0" all calls to gsound_context_play_simple() or `play_full()` will fail with GSOUND_ERROR_DISABLED. If the list of attributes is handed on to the sound server this attribute is stripped from it. A special attribute that can be used to control on which channel a sound is played. The value should be one of mono, front-left, front-right, front-center, rear-left, rear-right, rear-center, lfe, front-left-of-center, front-right-of-center, side-left, side-right, top-center, top-front-left, top-front-right, top-front-center, top-rear-left, top-rear-right, top-rear-center. This attribute is only honoured by some backends, other backends may choose to ignore it completely. If the list of attributes is handed on to the sound server this attribute is stripped from it. A special attribute that can be used to control the volume this sound event is played in if the backend supports it. A floating point value for the decibel multiplier for the sound. 0 dB relates to zero gain, and is the default volume these sounds are played in. If the list of attributes is handed on to the sound server this attribute is stripped from it. A special attribute that can be used to control the XDG sound theme that is used for this sample. If the list of attributes is handed on to the sound server this attribute is stripped from it. A special attribute that can be used to control the XDG sound theme output profile that is used for this sample. If the list of attributes is handed on to the sound server this attribute is stripped from it. A descriptive string for the sound event. Localized if possible and applicable. A textual id for an event sound, as mandated by the XDG sound naming specification. If this sound event was triggered by a mouse input event, the number of the mouse button that triggered it, formatted as string. 1 for left mouse button, 3 for right, 2 for middle. If this sound event was triggered by a mouse input event, the X position of the mouse cursor as fractional value between 0 and 1, formatted as string, 0 reflecting the left side of the screen, 1 the right side. If this sound event was triggered by a mouse input event, the Y position of the mouse cursor as fractional value between 0 and 1, formatted as string, 0 reflecting the top end of the screen, 1 the bottom end. If this sound event was triggered by a mouse input event, the X position of the mouse cursor on the screen, formatted as string. If this sound event was triggered by a mouse input event, the Y position of the mouse cursor on the screen, formatted as string. The artist of this media. Localized if possible and applicable. The file name this media was or can be loaded from. An icon for this media in binary PNG format. An icon name as defined in the XDG icon naming specifcation. The language this media is in, in some standard POSIX locale string, such as "de_DE". A name describing the media being played. Localized if possible and applicable. The "role" this media is played in. For event sounds the string "event". For other cases strings like "music", "video", "game", ... A (song) title describing the media being played. Localized if possible and applicable. If this sound event was triggered by a window on the screen and the windowing system supports multiple desktops, a comma seperated list of indexes of the desktops this window is visible on. If this attribute is an empty string, it is visible on all desktops (i.e. 'sticky'). The first desktop is 0. (e.g. "0,2,3") If this sound event was triggered by a window on the screen, the pixel height of the window. If this sound event was triggered by a window on the screen, the X position of the center of the window as fractional value between 0 and 1, formatted as string, 0 reflecting the left side of the screen, 1 the right side. If this sound event was triggered by a window on the screen, binary icon data in PNG format for this window. If this sound event was triggered by a window on the screen, an icon name for this window, as defined in the XDG icon naming specification. If this sound event was triggered by a window on the screen, some identification string for this window, so that the sound system can recognize specific windows. If this sound event was triggered by a window on the screen, the name of this window as human readable string. If this sound event was triggered by a window on the screen, the Y position of the center of the window as fractional value between 0 and 1, formatted as string, 0 reflecting the top side of the screen, 1 the bottom side. If this sound event was triggered by a window on the screen, the pixel width of the window. If this sound event was triggered by a window on the screen, the X position of the window measured from the top left corner of the screen to the top left corner of the window. If this sound event was triggered by a window on the screen and the windowing system is X11, the X display name of the window (e.g. ":0"). If this sound event was triggered by a window on the screen and the windowing system is X11, the X monitor id of the window formatted as string (e.g. "0"). If this sound event was triggered by a window on the screen and the windowing system is X11, the X screen id of the window formatted as string (e.g. "0"). If this sound event was triggered by a window on the screen and the windowing system is X11, the XID of the window formatted as string. If this sound event was triggered by a window on the screen, the y position of the window measured from the top left corner of the screen to the top left corner of the window. ca: the wrapped context Wrapper for ca_context. Creates and initializes a new #GSoundContext. If the an error occured during initialization, #NULL is returned and @error will be set appropriately. A new #GSoundContext A #GCancellable, or %NULL Requests that a sound be cached on the server. See [#caching][gsound-GSound-Context#caching]. %TRUE on success A #GSoundContext Return location for error A %NULL-terminated list of attribute-value pairs Requests that a sound be cached on the server. See [#caching][gsound-GSound-Context#caching]. This function is intented to be used by language bindings. A #GSoundContext Hash table of attrerties Attempts to open a connection to the backend sound driver. It is recommended that you set context attributes with gsound_context_set_attributes() before calling this function. > A connection is automatically opened before playing or caching sounds, > so you rarely need to call this yourself. %TRUE if the output device was opened successfully, or %FALSE (populating @error) A #GSoundContext Asynchronously request a sound to be played. When playback is finished (or if an error occurs) then @callback will be called, following the normal GIO async pattern. If playback is cancelled via @cancellable, then @callback will be called with #G_IO_ERROR_CANCELLED. If you do not need notification of when playback is complete, you should use gsound_context_play_simple(). A #GSoundContext A #GCancellable, or %NULL callback User data passed to @callback A %NULL-terminated list of attribute-value pairs Finish an async operation started by gsound_context_play_full(). You must call this function in the callback to free memory and receive any errors which occurred. %TRUE if playing finished successfully A #GSoundContext Result object passed to the callback of gsound_context_play_full() Asynchronously request a sound to be played. When playback is finished (or if an error occurs) then @callback will be called, following the normal GIO async pattern. If playback is cancelled via @cancellable, then @callback will be called with #G_IO_ERROR_CANCELLED. If you do not need notification of when playback is complete, you should use gsound_context_play_simple(). This function is intented to be used by language bindings. A #GSoundContext Attributes A #GCancellable, or %NULL callback user_data The basic "fire-and-forget" play command. This function will not block, and just sends a request to the sound server before immediately returning. If you need to know when a sound finishes playing then you should call gsound_context_play_full() instead. You can cancel playback at any time by calling g_cancellable_cancel() on @cancellable, if supplied. %TRUE on success, or %FALSE, populating @error A #GSoundContext A #GCancellable, or %NULL Return location for error, or %NULL A %NULL-terminated list of attribute-value pairs The basic "fire-and-forget" play command. This function will not block, and just sends a request to the sound server before immediately returning. If you need to know when a sound finishes playing then you should call gsound_context_play_full() instead. You can cancel playback at any time by calling g_cancellable_cancel() on @cancellable, if supplied. This function is intented to be used by language bindings. %TRUE on success, %FALSE on error A #GSoundContext Attributes A #GCancellable Set attributes or change attributes on @context. Subsequent calls to this function calling the same attributes will override the earlier values. Note that GSound will set the #GSOUND_ATTR_APPLICATION_NAME and #GSOUND_ATTR_APPLICATION_ID for you if using #GApplication, so you do not normally need to set these yourself. %TRUE if attributes were updated successfully A #GSoundContext Return location for error %NULL terminated list of attribute name-value pairs Set attributes or change attributes on @context. Subsequent calls to this function calling the same attributes will override the earlier values. Note that GSound will set the #GSOUND_ATTR_APPLICATION_NAME and #GSOUND_ATTR_APPLICATION_ID for you if using #GApplication, so you do not normally need to set these yourself. This function is intented to be used by language bindings. %TRUE if attributes were updated successfully A #GSoundContext Hash table of attributes to set Sets the libcanberra driver to @driver, for example "pulse", "alsa" or "null". You normally do not need to set this yourself. Note that this function may return %TRUE even if the specified driver is not available: see the libcanberra documentation for details. %TRUE if the libcanberra driver was set successfully A #GSoundContext libcanberra driver to use Attributes which can be applied to a #GSoundContext or passed to one of the `play()` or `cache()` methods. A #GSoundContext is used for playing system sounds. The typical use pattern is: * Initialize the #GSoundContext * [Optional] Set any global attributes using gsound_context_set_attributes() * [Optional] Cache any frequently-used sounds (for example, sound effects for a game) using gsound_context_cache() * Play sounds using gsound_context_play_simple() or gsound_context_play_full() * Close the connection to the sound server and clean up the context using g_object_unref() #GSoundContext implements the #GInitable interface, so if created with g_object_new() (as typically happens with language bindings) then you must call the g_initable_init() method before attempting to use it. # Simple Examples In C: |[<!-- language="C" --> GSoundContext *ctx = NULL; GCancellable *cancellable = g_cancellable_new(); GError *error = NULL; ctx = gsound_context_new(cancellable, &error); if (error) { // handle error } gsound_context_play_simple(ctx, cancellable, &error, GSOUND_ATTR_EVENT_ID, "phone-incoming-call", // other attributes... NULL); ]| or, using Python via GObject Introspection: |[<!-- language="Python" --> from gi.repository import GSound ctx = GSound.Context() try: ctx.init(); ctx.play_simple({ GSound.ATTR_EVENT_ID : "phone-incoming-call" }) except: # Handle error pass ]| or using Vala: |[<!-- language="Vala" --> try { var ctx = new GSound.Context(); ctx.play_simple(null, GSound.Attribute.EVENT_ID, "phone-incoming-call"); } catch (Error e) { // handle error } ]| # `play_simple()` versus `play_full()` The above examples use the gsound_context_play_simple() method for playing sounds. This is a "fire and forget" method which returns immediately and does not block your program, and is suitable for most use cases. If you need to find out when the sound finished (for example to repeat the sound) then you can use the gsound_context_play_full() version. This is an asynchronous method using the standard GIO async pattern, which will run the supplied #GAsyncReadyCallback when the sound server has finished. It is guaranteed that the callback will be run exactly once. Note that calling gsound_context_play_full() with a %NULL callback is not equivalent to calling gsound_context_play_simple(). When calling play_simple(), errors which occur before the sound is passed to the sound server are reported immediately, whereas with `play_full()` these are reported in the callback. If you pass a %NULL callback to gsound_context_play_full() you will not be able to receive these errors, so it is strongly recommended to avoid doing this and use gsound_context_play_simple() in the case when you don't need to be notified when the sound has finished. # Passing Attributes GSound supplies information to the sound server by means of attributes. Attributes can be set on the #GSoundContext itself using gsound_context_set_attributes(), or supplied in a `play()` call. Attributes set on the context will automatically applied to any subsequent `play()` calls, unless overridden by that call. In C and Vala, attributes are passed as %NULL-terminated list of (attribute, value) pairs. When using GObject introspection, attributes are typically passed using a language-specific associated array, for example a dict in Python or an object in JavaScript. For the list of attributes supported by GSound, see [GSound Attributes][gsound-GSound-Attributes]. # Caching # {#caching} If supported by the sound server, frequently-used sounds may be cached. This may be useful, for example, for sound effects in a game. To cache a sound, either call gsound_context_cache(), or pass the special #GSOUND_ATTR_CANBERRA_CACHE_CONTROL attribute to one of the `play()` functions. For example, in the startup code for a game you might include something like the following (error checking omitted): |[ <-- language="C" --> GSoundContext *ctx = gsound_context_new (NULL, NULL); gsound_context_cache(ctx, NULL, GSOUND_ATTR_MEDIA_FILENAME, "/path/to/player-spaceship-fire-laser.ogg", NULL); ]| There are three caching modes available, "permanent", "volatile" and "never". The default mode when calling gsound_context_cache() is "permanent", and the default mode for gsound_context_play_simple() and `play_full()` is "never". See the documentation for #GSOUND_ATTR_CANBERRA_CACHE_CONTROL for more details.