Controlling/querying your squeezeplayer

Retrieving players

Once you’ve got your server, you’ll want to get your players next.

It’s easy to get the list of the players currently attached to your server:

from LMSTools import LMSServer

# Define your server address

# create the server object
server = LMSServer(SERVER_IP)

# get the attached players
players = server.get_players()

Each item in ‘players’ will be a LMSPlayer instance and should be easily identifiable by printing the output of the list.

[LMSPlayer: Living Room (40:40:40:40:40:40),
 LMSPlayer: PiRadio (41:41:41:41:41:41),
 LMSPlayer: elParaguayo's Laptop (42:42:42:42:42:42)]
>>>laptop = server.get_players()[2]
LMSPlayer: elParaguayo's Laptop (42:42:42:42:42:42)

So, now you’ve got your player, what can you do with it?

Controlling the player

It’s easy to do simple manipulation of the playlist.

The player has methods to play, pause and skip tracks.


Changing volume

Players have a volume property. This can be used to retrieve the current volume level and adjust it. In addition there are volume_up and volume_down methods.

>>># Get the volume level
>>>laptop.volume = 90

Syncing players

You can sync and unsync players easily.

>>>livingroom = server.get_players()[0]
LMSPlayer: Living Room (40:40:40:40:40:40

You can confirm which players are synced with your player:

[LMSPlayer: Living Room (40:40:40:40:40:40]

If there are multiple sync groups then you can view members by using the show_players_sync_status method.

Adding tracks to the playlist

If you have a path to a playable item, these can be added to the playlist directly.

>>># You can use spotify urls if the app is installed

The playlist_insert and playlist_add methods can be used to place tracks at different locations in the playlist (i.e. next and last) while playlist_delete can be used to remove tracks.


Getting metadata

In case you don’t know what’s actually playing at the moment, you can retrieve metadata about the track (and other items in the playlist).

u'Public Service Broadcasting'
u'The Race For Space'

You can attempt to get a URL for the current track’s artwork via the track_artwork property.

If you want to query the playlist, there are a number of options open to you. See: playlist_get_info, playlist_get_detail and playlist_get_current_detail.

[{u'album': u'The Race For Space',
  u'artist': u'Public Service Broadcasting',
  u'coverart': u'0',
  u'coverid': u'-186029800',
  u'duration': u'252',
  u'id': u'-186029800',
  u'playlist index': 0,
  u'remote': 1,
  u'title': u'Go!'}]

Additional information can be requested by using tags.

>>>from LMSTools import LMSTags as tags
>>>laptop.playlist_get_current_detail(taglist=[tags.DURATION, tags.CONTENT_TYPE])
[{u'duration': u'252',
  u'id': u'-186029800',
  u'playlist index': 0,
  u'title': u'Go!',
  u'type': u'Ogg Vorbis (Spotify)'}]

…and more

See the class documentation for LMSPlayer for further information on available properties and methods.