mopidy.audio
— Audio API
The audio API is the interface we have built around GStreamer to support our specific use cases. Most backends should be able to get by with simply setting the URI of the resource they want to play, for these cases the default playback provider should be used.
For more advanced cases such as when the raw audio data is delivered outside of GStreamer or the backend needs to add metadata to the currently playing resource, developers should sub-class the base playback provider and implement the extra behaviour that is needed through the following API:
- class mopidy.audio.Audio(config, mixer) None [source]
Audio output through GStreamer.
- enable_sync_handler() None [source]
Enable manual processing of messages from bus.
Should only be used by tests.
- Return type:
- get_current_tags() dict[str, list[Any]] [source]
Get the currently playing media’s tags.
If no tags have been found, or nothing is playing this returns an empty dictionary. For each set of tags we collect a tags_changed event is emitted with the keys of the changed tags. After such calls users may call this function to get the updated values.
- mixer: SoftwareMixerAdapter | None = None
The software mixing interface
mopidy.audio.actor.SoftwareMixerAdapter
- on_start() None [source]
Run code at the beginning of the actor’s life.
Hook for doing any setup that should be done after the actor is started, but before it starts processing messages.
For
ThreadingActor
, this method is executed in the actor’s own thread, while__init__()
is executed in the thread that created the actor.If an exception is raised by this method the stack trace will be logged, and the actor will stop.
- Return type:
- on_stop() None [source]
Run code at the end of the actor’s life.
Hook for doing any cleanup that should be done after the actor has processed the last message, and before the actor stops.
This hook is not called when the actor stops because of an unhandled exception. In that case, the
on_failure()
hook is called instead.For
ThreadingActor
this method is executed in the actor’s own thread, immediately before the thread exits.If an exception is raised by this method the stack trace will be logged, and the actor will stop.
- Return type:
- pause_playback() bool [source]
Notify GStreamer that it should pause playback.
Returns
True
if successful, elseFalse
.- Return type:
- prepare_change() bool [source]
Notify GStreamer that we are about to change state of playback.
This function MUST be called before changing URIs or doing changes like updating data that is being pushed. The reason for this is that GStreamer will reset all its state when it changes to
Gst.State.READY
.- Return type:
- set_about_to_finish_callback(callback) None [source]
Configure audio to use an about-to-finish callback.
This should be used to achieve gapless playback. For this to work the callback MUST call
set_uri()
with the new URI to play and block until this call has been made.prepare_change()
is not needed beforeset_uri()
in this one special case.- Parameters:
callable – Callback to run when we need the next URI.
- Return type:
- set_source_setup_callback(callback) None [source]
Configure audio to use a source-setup callback.
This should be used to modify source-specific properties such as login details.
- Parameters:
callable – Callback to run when we setup the source.
- Return type:
- set_uri(uri, live_stream=False, download=False) None [source]
Set URI of audio to be played.
You MUST call
prepare_change()
before calling this method.
- start_playback() bool [source]
Notify GStreamer that it should start playback.
Returns
True
if successful, elseFalse
.- Return type:
- state: PlaybackState = 'stopped'
The GStreamer state mapped to
mopidy.audio.PlaybackState
Audio listener
- class mopidy.audio.AudioListener[source]
Marker interface for recipients of events sent by the audio actor.
Any Pykka actor that mixes in this class will receive calls to the methods defined here when the corresponding events happen in the core actor. This interface is used both for looking up what actors to notify of the events, and for providing default implementations for those listeners that are not interested in all events.
- position_changed(position) None [source]
Called whenever the position of the stream changes.
MAY be implemented by actor.
- reached_end_of_stream() None [source]
Called whenever the end of the audio stream is reached.
MAY be implemented by actor.
- Return type:
- static send(event, **kwargs) None [source]
Helper to allow calling of audio listener events.
- Return type:
- state_changed(old_state, new_state, target_state) None [source]
Called after the playback state have changed.
Will be called for both immediate and async state changes in GStreamer.
Target state is used to when we should be in the target state, but temporarily need to switch to an other state. A typical example of this is buffering. When this happens an event with old=PLAYING, new=PAUSED, target=PLAYING will be emitted. Once we have caught up a old=PAUSED, new=PLAYING, target=None event will be be generated.
Regular state changes will not have target state set as they are final states which should be stable.
MAY be implemented by actor.
- Parameters:
old_state (
mopidy.audio.PlaybackState
) – the state before the changenew_state (
mopidy.audio.PlaybackState
) – the state after the changetarget_state (
mopidy.audio.PlaybackState
orNone
if this is a final state.) – the intended state
- Return type:
- stream_changed(uri) None [source]
Called whenever the audio stream changes.
MAY be implemented by actor.
- Parameters:
uri (string) – URI the stream has started playing.
- Return type:
- tags_changed(tags) None [source]
Called whenever the current audio stream’s tags change.
This event signals that some track metadata has been updated. This can be metadata such as artists, titles, organization, or details about the actual audio such as bit-rates, numbers of channels etc.
For the available tag keys please refer to GStreamer documentation for tags.
MAY be implemented by actor.
Audio scanner
- class mopidy.audio.scan.Scanner(timeout=1000, proxy_config=None) None [source]
Helper to get tags and other relevant info from URIs.
- Parameters:
- scan(uri, timeout=None) _Result [source]
Scan the given uri collecting relevant metadata.
- Parameters:
uri (string) – URI of the resource to scan.
timeout (int) – timeout for scanning a URI in ms. Defaults to the
timeout
value used when creating the scanner.
- Return type:
_Result
- Returns:
A named tuple containing
(uri, tags, duration, seekable, mime)
.tags
is a dictionary of lists for all the tags we found.duration
is the length of the URI in milliseconds, orNone
if the URI has no duration.seekable
is boolean. indicating if a seek would succeed.
Audio utils
- class mopidy.audio.utils.Signals None [source]
Helper for tracking gobject signal registrations.
- mopidy.audio.utils.clocktime_to_millisecond(value) DurationMs [source]
Convert an internal GStreamer time to millisecond time.
- mopidy.audio.utils.millisecond_to_clocktime(value) int [source]
Convert a millisecond time to internal GStreamer time.
- Return type: