Skip to content

Commit

Permalink
Implement seek command (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon authored Nov 9, 2024
1 parent c90ac85 commit 3cf75ba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/linkplay/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ async def play_preset(self, preset_number: int) -> None:
)
await self.bridge.request(LinkPlayCommand.PLAY_PRESET.format(preset_number))

async def seek(self, position: int) -> None:
"""Seek to a position."""
if (
self.total_length_in_seconds > 0
and position >= 0
and position <= self.total_length_in_seconds
):
await self.bridge.request(LinkPlayCommand.SEEK.format(position))

@property
def muted(self) -> bool:
"""Returns if the player is muted."""
Expand Down Expand Up @@ -217,6 +226,16 @@ def total_length(self) -> int:
"""Returns the total length of the track in milliseconds."""
return int(self.properties.get(PlayerAttribute.TOTAL_LENGTH, 0))

@property
def current_position_in_seconds(self) -> int:
"""Returns the current position of the track in seconds."""
return int(int(self.properties.get(PlayerAttribute.CURRENT_POSITION, 0)) / 1000)

@property
def total_length_in_seconds(self) -> int:
"""Returns the total length of the track in seconds."""
return int(int(self.properties.get(PlayerAttribute.TOTAL_LENGTH, 0)) / 1000)

@property
def status(self) -> PlayingStatus:
"""Returns the current playing status."""
Expand Down

0 comments on commit 3cf75ba

Please sign in to comment.