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

Conversation

n18abdel
Copy link
Contributor

@n18abdel n18abdel commented Oct 3, 2022

No description provided.

@emontnemery
Copy link
Collaborator

This looks good, thanks @n18abdel 👍

Can you add an example setting playback rate, or give an example of a cast service which supports setting the playback rate?

@n18abdel
Copy link
Contributor Author

Sure here is an example, using the default media receiver on a SHIELD Android TV
PS: it seems like speeds outside of the 0.5-2 range are not supported, but I cannot say for sure

from time import sleep

import pychromecast
from pychromecast import quick_play

# Change to the friendly name of your Chromecast
CAST_NAME = "SHIELD"
APP_NAME = "default_media_receiver"
SPEEDS = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2]

# Change to an audio or video url
MEDIA_URL = (
    "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
)

cast: pychromecast.Chromecast = pychromecast.get_listed_chromecasts(
            friendly_names=[CAST_NAME]
        )[0][0]
cast.wait()
app_data = {"media_id": MEDIA_URL}
quick_play.quick_play(cast, APP_NAME, app_data)
cast.media_controller.block_until_active()

for speed in SPEEDS:
    print(f"Setting playback rate to {speed}")
    cast.media_controller.set_playback_rate(speed)
    sleep(10)

Copy link
Collaborator

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @n18abdel 👍

@emontnemery emontnemery merged commit 0048d87 into home-assistant-libs:master Feb 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants