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)
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...
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
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
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?
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
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
Learn how to link things together with TimeSquAir (http://TimeSquAir.io) and IBM's Node-RED (http://nodered.org)
and discover the other Instructables: