sublime_music.players.base module

class sublime_music.players.base.Player(on_timepos_change, on_track_end, on_player_event, player_device_change_callback, config)[source]

Bases: abc.ABC

Parameters
abstract __init__(on_timepos_change, on_track_end, on_player_event, player_device_change_callback, config)[source]

Initialize the player.

Parameters
property can_start_playing_with_no_latency: bool
Returns

whether the player can start playing a song with no latency.

abstract change_settings(config)[source]

This function is called when the player settings are changed (normally this happens when the user changes the settings in the UI).

Parameters

config (Dict[str, Union[str, int, bool]]) – A dictionary of configuration key -> configuration value.

abstract property enabled: bool
property gapless_playback: bool
Returns

whether the player supports and is using gapless playback

abstract static get_configuration_options()[source]
Returns

a dictionary of configuration key -> type of the option or tuple of options (for a dropdown menu).

Return type

Dict[str, Union[Type, Tuple[str, …]]]

abstract get_is_muted()[source]
Returns

whether or not the player is muted.

Return type

bool

abstract get_volume()[source]
Returns

the current volume on a scale of [0, 100]

Return type

float

abstract property name: str
Returns

returns the friendly name of the player for display in the UI.

abstract next_media_cached(uri, song)[source]
Parameters
abstract pause()[source]

Pause the player.

abstract play()[source]

Play the current media.

abstract play_media(uri, progress, song)[source]
Parameters
abstract property playing: bool
Returns

whether or not the player is currently playing a song.

abstract refresh_players()[source]

This function is called when the user requests the player list to be refreshed in the UI.

This function should call the player_device_change_callback with the delta events to indicate changes to the UI. If there is no reason to refresh (for example, the MPV player), then this function can do nothing.

abstract reset()[source]

Reset the player.

abstract seek(position)[source]
Parameters

position (datetime.timedelta) – seek to the given position in the song.

abstract set_current_device_id(device_id)[source]

Switch to the given device ID.

Parameters

device_id (str) –

abstract set_muted(muted)[source]
Parameters

muted (bool) – set the player’s “muted” property to the given value.

abstract set_volume(volume)[source]

Set the volume of the player to the given value.

Parameters

volume (float) – the value to set the volume to. Will be in the range [0, 100]

abstract shutdown()[source]

Do any cleanup of the player.

song_loaded = False
abstract property supported_schemes: Set[str]
Returns

a set of all the schemes that the player can play.

class sublime_music.players.base.PlayerDeviceEvent(delta: sublime_music.players.base.PlayerDeviceEvent.Delta, player_type: Type, id: str, name: str)[source]

Bases: object

Parameters
Return type

None

class Delta(value)[source]

Bases: enum.Enum

An enumeration.

ADD = 0
REMOVE = 1
__init__(delta, player_type, id, name)
Parameters
Return type

None

delta: sublime_music.players.base.PlayerDeviceEvent.Delta
id: str
name: str
player_type: Type
class sublime_music.players.base.PlayerEvent(type, device_id, playing=None, volume=None, stream_cache_duration=None)[source]

Bases: object

Represents an event triggered by the player. This is a way to signal state changes to Sublime Music if the player can be controlled outside of Sublime Music (for example, Chromecast player).

Each player event has a PlayerEvent.EventType. Additionally, each event type has additional information in the form of additional properties on the PlayerEvent object.

Parameters
Return type

None

class EventType(value)[source]

Bases: enum.Enum

An enumeration.

CONNECTED = 4
CONNECTING = 3
DISCONNECT = 5
PLAY_STATE_CHANGE = 0
STREAM_CACHE_PROGRESS_CHANGE = 2
VOLUME_CHANGE = 1
__init__(type, device_id, playing=None, volume=None, stream_cache_duration=None)
Parameters
Return type

None

device_id: str
playing: Optional[bool] = None
stream_cache_duration: Optional[float] = None
type: sublime_music.players.base.PlayerEvent.EventType
volume: Optional[float] = None