I have some files lying around in my computer with movies I want to watch. The process typically involves copying the file over to a pendrive, plug that into the TV and use the TV media player. This works very well, but I am lazy. It also happens that I have a Chromecast on my dumb TV. It would be very convenient for me to figure out a way of sending directly files from my computer to the Chromecast. It turns out it's not difficult at all.
1. Install PyChromecast
PyChromecast is a wonderful Python library (3.4+) that allows you to send videos to your Chromecast at home. It handles everything, from device detection, to buffering, to play / pause / several controls.
I have an old-ish Ubuntu 14.04, but this did the trick:
# I like to keep stuff tidy virtualenv -p /usr/bin/python3 ~/virtualenv/pychromecast source ~/virtualenv/pychromecast/bin/activate pip3 install pychromecast
2. Start a local HTTP server
Just go to the folder where you have the videos and start a
python -m SimpleHTTPServer
Leave that running on the background. We're almost there.
3. Send the video to your Chromecast
This might be different for you, as I only have one Chromecast at home, so my device will always be the first from the list of detected devices, but this is my test script:
import pychromecast if __name__ == "__main__": cast = pychromecast.get_chromecasts() mc = cast.media_controller mc.play_media("http://192.168.0.103:8000/video_test.mp4", content_type = "video/mp4") mc.block_until_active() mc.play()
At first I was trying to send the file directly, but that didn't work. The
example provided in the documentation took the file from a web server, so I
thought that perhaps Chromecast can't receive a file but can receive an URL with
the contents of the video. That
192.168.0.103 up there is the internal IP of
And we're good to go. Please note that this script will return as soon as the
movie is playing, so you won't have access to that
mc object anymore. If would
be better to run it inside a Python terminal, so you can always go back and
pause or stop the stream if needed.