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)
""" Example code to show how you can start a YouTube movie whenever the idle screen is shown. """ 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)
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)
""" Examples of how PyChromecast can be used. """ from __future__ import print_function import time import pychromecast as pc cast = pc.get_chromecast() print(cast.device) print("Current app:", cast.app) # 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("kxopViU98Xo", cast=cast) 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(10) print("Ramp:", ramp) print("Toggling play status")
#!/usr/bin/python import time, sys if (len(sys.argv) > 0): video = sys.argv[1] else: video = "REjj1ruFQww" try: import pychromecast pychromecast.play_youtube_video(video, pychromecast.PyChromecast().host) except: pass
#!/usr/bin/python import time, sys if(len(sys.argv) > 0): video = sys.argv[1] else: video = "REjj1ruFQww" try: import pychromecast pychromecast.play_youtube_video(video, pychromecast.PyChromecast().host) except: pass
def play_youtube_video(self, video_id): """ Plays specified video_id on the Chromecast's YouTube channel. """ pychromecast.play_youtube_video(video_id, self.cast.host)