Play Youtube Stream Sound on TimeSQuAir (Raspberry Pi)

by thethingbox in Circuits > Raspberry Pi

5676 Views, 11 Favorites, 0 Comments

Play Youtube Stream Sound on TimeSQuAir (Raspberry Pi)

TSA_youtube.jpg
Capture_1.JPG

You want to stream some music available on Youtube, and we understand you! Such a huge collection available for free! Follow this 5-minute recipe, and you'll be able to listen to your favorite songs!

First of all, here come the ingredient:

  • 1 TimeSquAir
  • 1 sound speaker

Let's start!

First, Two Small Technical Actions...

Capture_1-1.JPG

We need first to install appropriate softwares on the TimeSquAir to start. Don't worry, even if you're not comfortable with this, just follow what's written.

Open a SSH session (follow this instructable if you don't know how to do)

Install Python by typing the following command on the SSH window:
apt-get install python-pip

Install the LiveStreamer software by typing the following command:
pip install -U livestreamer

You're done with this step! You can close the SSH window

Create the Dedicated Flow

Capture_2.JPG
Capture_3.JPG
Capture_4.JPG
Capture_5.JPG
Capture_6.JPG

Now we can build the flow responsible for reading youtube links.

Let's start with the node containing the Youtube URL.

Then a function putting this url in msg.url:
msg.url = msg.payload ;
return msg;

Let's put a command killing all the eventual running omxplayer jobs:
killall omxplayer.bin

Then, we build the command in a small function:
msg.payload = msg.url + " best --player \"omxplayer\" --fifo --yes-run-as-root " ;
return msg;

And finally, we launch livestreamer. Don't forget to "append msg.payload" in the command window (this will add the complete argument previously calculated to the livestreamer command)

Some Youtube Links Might Cause an Error

Capture_7.JPG
Capture_8.JPG

Some youtube links might result in an error while trying to process livestreamer. In order to know what happens, we suggest to put some debug display nodes as shown on the picture.

How to Stop the Stream?

Capture_10.JPG

In order to stop the ongoing audio stream, just put the following command, with the wanted launching method (here a simple Go Node):
killall omxplayer.bin

Going Further

Capture_9.JPG

Know that you can play audio from youtube links, you can certainly improve the system. Examples:

  • Store your preferred youtube links
  • Use NFC tags to launch them, or stop the stream
  • Use NFC tags to increase / decrease the volume
  • Use this as an alarm clock by launching a youtube link at the desired time.
  • ...

Learn More

tsa.jpg