Skip to content

Commit

Permalink
[ 1.0.43 ] * Updated service player_media_play_context to correctly…
Browse files Browse the repository at this point in the history
… default the `position_ms` and `offset_position` argument values. This was causing the playlist to always start at the first track if the `offset_position` argument value was not supplied. This manifested itself when shuffle was enabled, as the playlist should have started at a random track and was not doing so.

  * Updated service `player_media_play_tracks` to correctly default the `position_ms` argument value.
  • Loading branch information
thlucas1 committed Jul 23, 2024
1 parent 0f3bba4 commit f75c83c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.43 ] - 2024/07/23

* Updated service `player_media_play_context` to correctly default the `position_ms` and `offset_position` argument values. This was causing the playlist to always start at the first track if the `offset_position` argument value was not supplied. This manifested itself when shuffle was enabled, as the playlist should have started at a random track and was not doing so.
* Updated service `player_media_play_tracks` to correctly default the `position_ms` argument value.

###### [ 1.0.42 ] - 2024/07/23

* Added service `player_set_repeat_mode` that sets repeat mode for the specified Spotify Connect device.
Expand Down
6 changes: 3 additions & 3 deletions custom_components/spotifyplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@
vol.Required("entity_id"): cv.entity_id,
vol.Required("context_uri"): cv.string,
vol.Optional("offset_uri"): cv.string,
vol.Optional("offset_position", default=0): vol.All(vol.Range(min=0,max=500)),
vol.Optional("position_ms", default=0): vol.All(vol.Range(min=0,max=999999999)),
vol.Optional("offset_position", default=-1): vol.All(vol.Range(min=-1,max=500)),
vol.Optional("position_ms", default=-1): vol.All(vol.Range(min=-1,max=999999999)),
vol.Optional("device_id"): cv.string,
}
)
Expand All @@ -412,7 +412,7 @@
{
vol.Required("entity_id"): cv.entity_id,
vol.Required("uris"): cv.string,
vol.Optional("position_ms", default=0): vol.All(vol.Range(min=0,max=999999999)),
vol.Optional("position_ms", default=-1): vol.All(vol.Range(min=-1,max=999999999)),
vol.Optional("device_id"): cv.string,
}
)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"urllib3>=1.21.1,<1.27",
"zeroconf>=0.132.2"
],
"version": "1.0.42",
"version": "1.0.43",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
24 changes: 21 additions & 3 deletions custom_components/spotifyplus/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3300,12 +3300,12 @@ def service_spotify_player_media_play_context(self,
Example: `spotify:track:1301WleyT98MSxVHPZCA6M` start playing at the specified track Uri.
offsetPosition (int):
Indicates from what position in the context playback should start.
The value is zero-based, and can't be negative.
The value is zero-based, and must be a positive number, or -1 to disable positioning.
Only available when contextUri corresponds to an album or playlist.
Default is `0`.
Example: `3` start playing at track number 4.
positionMS (int):
The position in milliseconds to seek to; must be a positive number.
The position in milliseconds to seek to; must be a positive number, or -1 to disable positioning.
Passing in a position that is greater than the length of the track will cause the
player to start playing the next track.
Default is `0`.
Expand All @@ -3329,6 +3329,12 @@ def service_spotify_player_media_play_context(self,
apiMethodParms.AppendKeyValue("deviceId", deviceId)
_logsi.LogMethodParmList(SILevel.Verbose, "Spotify Player Media Play Context Service", apiMethodParms)

# validations.
if offsetPosition == -1:
offsetPosition = None
if positionMS == -1:
positionMS = None

# see if default device option was specified (e.g. deviceId="*").
deviceId = self._GetDefaultDeviceOption(deviceId)

Expand Down Expand Up @@ -3427,7 +3433,7 @@ def service_spotify_player_media_play_tracks(self,
Example: `spotify:track:4iV5W9uYEdYUVa79Axb7Rh,spotify:episode:512ojhOuo1ktJprKbVcKyQ`.
A maximum of 50 items can be added in one request.
positionMS (int):
The position in milliseconds to seek to; must be a positive number.
The position in milliseconds to seek to; must be a positive number, or -1 to disable positioning.
Passing in a position that is greater than the length of the track will cause the
player to start playing the next track.
Default is `0`.
Expand All @@ -3449,6 +3455,10 @@ def service_spotify_player_media_play_tracks(self,
apiMethodParms.AppendKeyValue("deviceId", deviceId)
_logsi.LogMethodParmList(SILevel.Verbose, "Spotify Player Media Play Tracks Service", apiMethodParms)

# validations.
if positionMS == -1:
positionMS = None

# see if default device option was specified (e.g. deviceId="*").
deviceId = self._GetDefaultDeviceOption(deviceId)

Expand Down Expand Up @@ -3574,6 +3584,8 @@ def service_spotify_player_set_repeat_mode(
_logsi.LogMethodParmList(SILevel.Verbose, "Spotify Player Set Repeat Mode Service", apiMethodParms)

# validations.
if deviceId == '':
deviceId = None
if deviceId is None or deviceId == "*":
deviceId = PlayerDevice.GetIdFromSelectItem(self.data.OptionDeviceDefault)

Expand Down Expand Up @@ -3633,6 +3645,8 @@ def service_spotify_player_set_shuffle_mode(
_logsi.LogMethodParmList(SILevel.Verbose, "Spotify Player Set Shuffle Mode Service", apiMethodParms)

# validations.
if deviceId == '':
deviceId = None
if deviceId is None or deviceId == "*":
deviceId = PlayerDevice.GetIdFromSelectItem(self.data.OptionDeviceDefault)

Expand Down Expand Up @@ -3691,6 +3705,8 @@ def service_spotify_player_set_volume_level(
_logsi.LogMethodParmList(SILevel.Verbose, "Spotify Player Set Volume Level Service", apiMethodParms)

# validations.
if deviceId == '':
deviceId = None
if deviceId is None or deviceId == "*":
deviceId = PlayerDevice.GetIdFromSelectItem(self.data.OptionDeviceDefault)

Expand Down Expand Up @@ -3743,6 +3759,8 @@ def service_spotify_player_transfer_playback(self,
# validations.
if play is None:
play = True
if deviceId == '':
deviceId = None
if deviceId is None or deviceId == "*":
deviceId = PlayerDevice.GetIdFromSelectItem(self.data.OptionDeviceDefault)

Expand Down

0 comments on commit f75c83c

Please sign in to comment.