Linux

Control Chromecast Devices From A Linux Desktop Via MPRIS Widgets Using chromecast_mpris


chromecast_mpris is a daemon that allows you to control Chromecast devices from your Linux desktop using MPRIS widgets. The tool can also be used to open media and play YouTube videos on your Chromecast from the command line.

MPRIS (Media Player Remote Interfacing Specification) support is available by default in the Plasma Desktop and Linux Mint, GNOME has a simple MPRIS widget in its Date / Time menu (and there are third-party extensions for this as well, like this MPRIS Indicator Button), playerctrl (a command line utility and library for controlling media players that implement the MPRIS D-Bus Interface Specification), etc.

chromecast_mpris GNOME Shell Indicator Button
chromecast_mpris controlling my Chromecast using the MPRIS Indicator Button extension for GNOME Shell

It’s worth noting that this program only works with devices that implement the Cast v2 API (it uses PyChromecast under the hood to control Chromecast devices), like Chromecasts, and some Cast-enabled devices like Google Home.

Even though it can play media on the Chromecast using the playerctl command, chromecast_mpris’ purpose is to serve as a remote control, in the same way the MPRIS interface works for every other player that uses it, e.g. Rhythmbox, VLC, etc.

Since this exposes MPRIS controls for your Chromecast, it means you can use your keyboard’s media keys to control the Chromecast.

chromecast_mpris features:

  • Control video and music playback
  • View playback information in real time
  • Display thumbnail, title, playback position and media length
  • Seek forward and backward, play, pause, and stop playback
  • Volume up and down
  • Play next and previous
  • Quit casted app
  • Open media and play YouTube videos from the command line (using playerctl)

The program does not have playlist support yet.

Below you’ll find a couple more screenshots of MPRIS widgets (under KDE Plasma and Cinnamon desktops) able to control a Chromecast device using chromecast_mpris:

chromecast_mpris KDE Plasma

chromecast_mpris Cinnamon Linux Mint

You might also like: How To Cast Your GNOME Shell Desktop To A Chromecast (With Audio, Wayland / X11 Support) Using Cast to TV

How to play media / YouTube videos on the Chromecast using chromecast_mpris and playerctl

Playing media / YouTube videos on the Chromecast requires knowing the device name. With chromecast_mpris installed and running, get the Chromecast device name using the following command:

playerctrl --list-all

Once you know the Chromecast name, play a media file using:

playerctl --player MyDevice open "URL"

Replacing MyDevice with the device name, and URL with the link to the media file.

Example from the chromecast_mpris project page:

playerctl --player MyDevice open "http://ccmixter.org/content/gmz/gmz_-_Parametaphoriquement.mp3"

Or, play a YouTube video:

playerctl --player MyDevice open "YoutubeURL"

Replacing MyDevice with the Chromecast name, and YoutubeURL with the link to the YouTube video.

Example:

playerctl --player MyDevice open "https://www.youtube.com/watch?v=Jg5wkZ-dJXA"

You might also like: CATT Command Line Chromecast Player

Install chromecast_mpris

The tool is available on AUR for Arch Linux / Manjaro users, and on PyPI from where it can easily be installed on any Linux distribution using PIP.

Once installed, run it, and you will be able to control your Chromecast from a MPRIS widget:

chromecast_mpris

I only have one Chromecast device, so I’m not sure how chromecast_mpris behaves when there are multiple devices available. [[Edit]] The tool does have an option to specify which Chromecast device to use:

chromecast_mpris --name "MyDevice"

Where MyDevice is the name of the Chromecast device.

If you want to add this to your startup applications, and you’ve installed this using PIP, make sure you enter the full path to the executable (/home/YOURUSERNAME/.local/bin/chromecast_mpris).

More Chromecast-related articles from Linux Uprising: