Cast to TV Gnome Shell Extension

Casting Pearls

Article from Issue 233/2020
Author(s):

Cast to TV is a Gnome extension that streams media files from a PC to a Chromecast-enabled device.

A Chromecast [1] is a small USB dongle that lets you stream audio-visual content from a mobile device to your TV. Just attach Chromecast to your TV, and you can stream to the TV using an Android or other device that supports Google Cast technology.

Google originally developed Chromecast to support streaming from Android phones, but the open source community has never been slow to grasp an opportunity. Cast to TV is a Gnome Shell extension that lets you send pictures, music, and video to a Chromecast-enabled TV from the Gnome desktop. And if you don't happen to have a Chromecast device, use the Playercast app on a Raspberry Pi or other Linux computer to receive the stream and act as an interface to your TV.

Cast to TV for Gnome

You'll find Cast to TV at the Gnome Extensions [2] website. Simply flip the switch from Off to On. For the installation to work, you also must install the native host connector and a browser add-on available for Chrome/Chromium and Firefox (see the "Installing Gnome Extensions" box).

Installing Gnome Extensions

To install from the Gnome Extensions web portal, the system must meet two requirements: Both the native host connector and the appropriate web browser add-on must be installed. On Debian, Ubuntu, and Linux Mint, first set up the host connector with the chrome-gnome-shell package, and then install the appropriate add-on for Chrome/Chromium [3] or Firefox [4]. The Gnome wiki describes the procedure for all other common distributions [5].

Cast to TV depends on the packages npm, nodejs, and ffmpeg. On the project's GitHub site, the developers provide installation instructions for all major Linux distributions [6]. The following command installs these background packages on a recent Ubuntu:

$ sudo apt install npm nodejs ffmpeg

Keep in mind that Node.js is a heavyweight with numerous sub-packages; the installation will take a while, especially on older machines.

When these packages are installed, a new entry appears in the Gnome menu in the upper right corner called Cast Media. Unfold it and open Cast Settings, from which you install the required Node Package Manager (npm) modules as a final step: Open Modules and click Install npm modules (Figure 1). In just a few seconds, the system installs all the required files on the computer.

Figure 1: For Cast to TV to work, you need to install the npm modules required by the program. A single click does the trick.

All requirements are now met and the configuration is complete. Now open the Gnome menu again and click Cast Media and then Turn On, which closes the menu. When you open the Gnome menu a third time, you will find a Cast Media entry with the sub-items Video, Music, and Picture, as well as Turn Off and the ubiquitous Cast Settings (Figure 2).

Figure 2: The Gnome menu in the panel lets you use Cast to TV to stream pictures, music, or videos to Chromecast-compatible devices, which include not only the Chromecast dongle itself, but also TV sets equipped with Android TV.

From Your Computer to the TV Set

Casting is now as easy as clicking on one of the media formats and selecting the files to play. Cast to TV lets you select several files in one step, as long as they are in the same directory. Then, you need to check the TV set, which should be playing the selected media files. Additionally, a new menu appears in the Gnome panel at the top of the screen labeled Chromecast. (See also the box "Two or More Chromecast Devices.")

Two or More Chromecast Devices

If you use multiple Chromecast dongles or Chromecast-enabled devices in your household, you need to tell Cast to TV the device to which you want to send the stream. For this purpose, go to the Cast Settings | Chromecast tab, and beside the Device selection item, Cast to TV lists all the Chromecast devices it finds. If necessary, devices that are not found can be configured manually by their IP addresses from the gear icon.

Clicking on the entry brings up a dialog in which you can find a progress bar, playback control buttons, and – after clicking Playback – a playlist (Figure 3). If you tap the Stop icon, Cast to TV immediately stops streaming and the menu disappears. From the Gnome menu, you can open Cast Settings during playback to pop up a lightweight configuration dialog where you can adjust the Chromecast menu.

Figure 3: You can control the playback of the streamed media from another menu. Use the slider to jump to another position in the track. Drag and drop to control the order of items in the playlist.

If you enable Nautilus | Nemo Integration under the Cast Settings | Other tab, it is even easier to select a video or track to stream. Restart the file manager completely (e.g., nautilus -q) to stop all background services, as well; a new Playercast entry appears in the context menu for multimedia files. With the Play Files and Add to Playlist options (Figure 4), you can then send the selected files to the Chromecast receiver.

Figure 4: Cast to TV integrates into the file manager. From the context menu for multimedia files, you can cast pictures, music, or videos directly from Nautilus to the Chromecast receiver.

On the other hand, Cast to TV cannot yet transfer the complete desktop to the TV. At press time, this function only worked with Chrome or Chromium by opening the web browser and selecting Cast from the menu. You will then find a new icon to the right of the address line. From this menu, you can choose between the Chromecast devices active on the network and the options to stream either a tab, the whole desktop, or a file (Figure 5). Note that streaming the desktop only works with the classic X server, not with Wayland. To switch desktops, you need to log out of the desktop and, after selecting the user account from the gear menu, select GNOME on Xorg.

Figure 5: The desktop cannot yet be streamed with Cast to TV; you still have to use the function integrated in Chrome or Chromium, although the solution did not work with Wayland at press time.

Installing Playercast

Even if you do not have a Chromecast dongle or a device with an integrated Chromecast receiver, you do not have to give up on the idea of streaming media content with Cast to TV. Equipped with Playercast [7], a Raspberry Pi connected to a TV over HDMI is the ideal receiver. (See also the "HDMI-CEC" box.) Alternatively, any other Linux PC will work, as well.

HDMI-CEC

Playercast cannot be controlled by a smartphone, but HDMI-CEC (Consumer Electronics Control) lets you forward control commands from your TV's remote control to devices connected over HDMI, so you can control playback without walking over to the streaming computer. The Raspberry Pi's Raspbian operating system supports this technology out of the box after you install the cec-utils package.

Playercast can be downloaded by npm to the computer you will be using to receive the streams, but first, you have to install npm and the MPV media player [8] as dependencies with the conventional package manager:

$ sudo apt install npm mpv
$ sudo npm install -g playercast
$ playercast <IP address>:<Port> ### Default port is 4000

Executing the playercast command on the third line tests the installation. The parameters are the IP address of the computer on which Cast to TV is installed and the port number (port 4000 in the standard configuration). Next, go to Cast Settings on the sending computer and change the Receiver type under the Main tab from Chromecast to Playercast app. As the Listening port, accept the default 4000.

Streaming with Cast to TV is now no longer any different from streaming with a Chromecast dongle. To select the desired media files, use Cast Media from the Gnome panel. The Gnome add-on then immediately transfers the data to the system equipped with Playercast – whether pictures, music, or videos. Again, an additional menu in the panel provides controls, but it is now labeled Playercast. The elements in the dialog are no different from those of the Chromecast variant.

Calling Playercast manually at every start-up is not very practical, especially if you install the system on a Raspberry Pi (e.g., in an attempt to make a "dumb" TV "smart"). Therefore, you should set up Playercast as a system service after completing the initial tests (Listing 1). Now, the software will start automatically when you power on the computer, which you can hide behind the TV set without a keyboard or mouse.

Listing 1

Playercast as a System Service

 

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News