Quantcast
Channel: Idiot Inside
Viewing all articles
Browse latest Browse all 26

Control Chromecast with Python

$
0
0

Python Chromecast

Thanks to the pychromecast library. It supports the following features,

  • Auto discovering connected Chromecasts on the network
  • Start the default media receiver and play any online media
  • Control playback of current playing media
  • Implement Google Chromecast api v2
  • Communicate with apps via channels
  • Easily extendable to add support for unsupported namespaces
  • Multi-room setups with Audio cast devices

How to use pychromecast?

Install pychromecast using pip.

pip install pychromecast
from __future__ import print_function
import time
import pychromecast

# Your Chromecast device Friendly Name
device_friendly_name = "VuCast"

chromecasts = pychromecast.get_chromecasts()

# select Chromecast device
cast = next(cc for cc in chromecasts if cc.device.friendly_name == device_friendly_name)

# wait for the device
cast.wait()
print(cast.device)
print(cast.status)

# get media controller 
mc = cast.media_controller
# set online video url
mc.play_media('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', 'video/mp4')

# blocks device
mc.block_until_active()
print(mc.status)

# plays the video
mc.play()

This is merely an example, This opens lot of possiblities controlling Chromecast with python.


Viewing all articles
Browse latest Browse all 26

Trending Articles