Skip to content

Commit

Permalink
Add set_playback_rate method (#660)
Browse files Browse the repository at this point in the history
* Add set_playback_rate method

* Update media.py

* Update media.py

---------

Co-authored-by: Erik Montnemery <[email protected]>
  • Loading branch information
n18abdel and emontnemery authored Feb 14, 2024
1 parent f1975e8 commit 0048d87
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 0048d87

Please sign in to comment.