GSound.Context

g GObject.GInterface GObject.GInterface Gio.Initable Gio.Initable GObject.GInterface->Gio.Initable GObject.Object GObject.Object GSound.Context GSound.Context GObject.Object->GSound.Context Gio.Initable->GSound.Context

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.Initable (2)

Structs:

GObject.ObjectClass (5)

class

new (cancellable)

cache (attrs)

open ()

play_full (attrs, cancellable, callback, *user_data)

play_full_finish (result)

play_simple (attrs, cancellable)

set_attributes (attrs)

set_driver (driver)

Virtual Methods

Inherited:

GObject.Object (7), Gio.Initable (1)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class GSound.Context(**kwargs)
Bases:

GObject.Object, Gio.Initable

Abstract:

No

Structure:

GSound.ContextClass

ca: the wrapped context Wrapper for ca_context.

classmethod new(cancellable)
Parameters:

cancellable (Gio.Cancellable or None) – A Gio.Cancellable, or None

Raises:

GLib.Error

Returns:

A new GSound.Context

Return type:

GSound.Context

Creates and initializes a new GSound.Context. If the an error occured during initialization, None is returned and error will be set appropriately.

cache(attrs)
Parameters:

attrs ({str: str}) – Hash table of attrerties

Raises:

GLib.Error

Return type:

bool

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.

open()
Raises:

GLib.Error

Returns:

True if the output device was opened successfully, or False (populating error)

Return type:

bool

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.

play_full(attrs, cancellable, callback, *user_data)
Parameters:

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 Gio.IOErrorEnum.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.

play_full_finish(result)
Parameters:

result (Gio.AsyncResult) – Result object passed to the callback of GSound.Context.play_full()

Raises:

GLib.Error

Returns:

True if playing finished successfully

Return type:

bool

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.

play_simple(attrs, cancellable)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False on error

Return type:

bool

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 Gio.Cancellable.cancel() on cancellable, if supplied.

This function is intented to be used by language bindings.

set_attributes(attrs)
Parameters:

attrs ({str: str}) – Hash table of attributes to set

Raises:

GLib.Error

Returns:

True if attributes were updated successfully

Return type:

bool

Set attributes or change attributes on self. 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 Gio.Application, so you do not normally need to set these yourself.

This function is intented to be used by language bindings.

set_driver(driver)
Parameters:

driver (str) – libcanberra driver to use

Raises:

GLib.Error

Returns:

True if the libcanberra driver was set successfully

Return type:

bool

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.