Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_playback_rate method #660

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion pychromecast/controllers/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TYPE_QUEUE_PREV = "QUEUE_PREV"
TYPE_QUEUE_UPDATE = "QUEUE_UPDATE"
TYPE_SEEK = "SEEK"
TYPE_SET_PLAYBACK_RATE = "SET_PLAYBACK_RATE"
TYPE_STOP = "STOP"

METADATA_TYPE_GENERIC = 0
Expand Down Expand Up @@ -151,7 +152,8 @@ def adjusted_current_time(self) -> float | None:
# Add time since last update
return (
self.current_time
+ (datetime.utcnow() - self.last_updated).total_seconds()
+ self.playback_rate
* (datetime.utcnow() - self.last_updated).total_seconds()
)
# Not playing, return last reported seek time
return self.current_time
Expand Down Expand Up @@ -660,6 +662,18 @@ def seek(self, position: float, timeout: float = 10.0) -> None:
)
response_handler.wait_response()

def set_playback_rate(self, playback_rate: float, timeout: float = 10.0) -> None:
"""Set the playback rate. 1.0 is regular time, 0.5 is slow motion."""
response_handler = WaitResponse(timeout, "set playback rate")
self._send_command(
{
MESSAGE_TYPE: TYPE_SET_PLAYBACK_RATE,
"playbackRate": playback_rate,
},
response_handler.callback,
)
response_handler.wait_response()

def queue_next(self, timeout: float = 10.0) -> None:
"""Send the QUEUE_NEXT command."""
response_handler = WaitResponse(timeout, "queue next")
Expand Down