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
on_track_end (Callable[[], None]) –
on_player_event (Callable[[sublime_music.players.base.PlayerEvent], None]) –
player_device_change_callback (Callable[[sublime_music.players.base.PlayerDeviceEvent], None]) –
- abstract __init__(on_timepos_change, on_track_end, on_player_event, player_device_change_callback, config)[source]
Initialize the player.
- Parameters
config (Dict[str, Union[str, int, bool]]) – A dictionary of configuration key -> configuration value.
on_track_end (Callable[[], None]) –
on_player_event (Callable[[sublime_music.players.base.PlayerEvent], None]) –
player_device_change_callback (Callable[[sublime_music.players.base.PlayerDeviceEvent], None]) –
- 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).
- abstract next_media_cached(uri, song)[source]
- Parameters
uri (str) – the URI to prepare to play. The URI is guaranteed to be one of the schemes in the
supported_schemes
set for this adapter.song (sublime_music.adapters.api_objects.Song) – the actual song.
- abstract play_media(uri, progress, song)[source]
- Parameters
uri (str) – the URI to play. The URI is guaranteed to be one of the schemes in the
supported_schemes
set for this adapter.progress (datetime.timedelta) – the time at which to start playing the song.
song (sublime_music.adapters.api_objects.Song) – the actual song. This could be used to set metadata and such on the player.
- 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 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]
- song_loaded = False
- class sublime_music.players.base.PlayerDeviceEvent(delta: sublime_music.players.base.PlayerDeviceEvent.Delta, player_type: Type, id: str, name: str)[source]
Bases:
object
- Parameters
delta (sublime_music.players.base.PlayerDeviceEvent.Delta) –
player_type (Type) –
id (str) –
name (str) –
- Return type
None
- __init__(delta, player_type, id, name)
- Parameters
delta (sublime_music.players.base.PlayerDeviceEvent.Delta) –
player_type (Type) –
id (str) –
name (str) –
- Return type
None
- 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 thePlayerEvent
object.PlayerEvent.EventType.PLAY_STATE_CHANGE
– indicates that the play state of the player has changed. ThePlayerEvent.playing
property is required for this event type.PlayerEvent.EventType.VOLUME_CHANGE
– indicates that the player’s volume has changed. The :classs`PlayerEvent.volume` property is required for this event type and should be in the range [0, 100].PlayerEvent.EventType.STREAM_CACHE_PROGRESS_CHANGE
– indicates that the stream cache progress has changed. When streaming a song, this will be used to show how much of the song has been loaded into the player. ThePlayerEvent.stream_cache_duration
property is required for this event type and should be a float represent the number of seconds of the song that have been cached.PlayerEvent.EventType.CONNECTING
– indicates that a device is being connected to. ThePlayerEvent.device_id
property is required for this event type and indicates the device ID that is being connected to.PlayerEvent.EventType.CONNECTED
– indicates that a device has been connected to. ThePlayerEvent.device_id
property is required for this event type and indicates the device ID that has been connected to.
- 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)