How to use the pychromecast.play_youtube_video function in PyChromecast

To help you get started, we’ve selected a few PyChromecast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BishopFox / rickmote / rickmote.py View on Github external
def PlayVideo(self):
        cast = pc.PyChromecast()
        print cast.device

        # Make sure an app is running that supports RAMP protocol
        if not cast.app or pc.PROTOCOL_RAMP not in cast.app.service_protocols:
            pc.play_youtube_video(YOUTUBE_SUFFIX, cast.host)
            cast.refresh()

        ramp = cast.get_protocol(pc.PROTOCOL_RAMP)

        # It can take some time to setup websocket connection
        # if we just switched to a new channel
        while not ramp:
            time.sleep(1)
            ramp = cast.get_protocol(pc.PROTOCOL_RAMP)

        # Give ramp some time to init
        time.sleep(1)
github balloob / pychromecast / example_youtube_as_idle_screen.py View on Github external
from __future__ import print_function
import time

import pychromecast

if __name__ == "__main__":
    cast = pychromecast.get_chromecast(strict=False)

    print(u"Monitoring {}".format(cast.device.friendly_name))

    while True:
        cast.refresh()

        if cast.app_id == pychromecast.APP_ID['HOME']:
            print("Hey, we are on the home screen :( Starting YouTube..")
            pychromecast.play_youtube_video("kxopViU98Xo", cast=cast)

        time.sleep(10)
github home-assistant / home-assistant / homeassistant / components / chromecast.py View on Github external
def play_youtube_video_service(service, video_id):
        """ Plays specified video_id on the Chromecast's YouTube channel. """
        if video_id:  # if service.data.get('video') returned None
            for entity_id, cast in _service_to_entities(service):
                pychromecast.play_youtube_video(video_id, cast.host)
                update_chromecast_state(entity_id, cast)