Ever wanted your Raspberry Pi to act as a network-controlled audio player? Pi Player accomplishes this goal. It consists of 3 components acting independently to make the system work.
- Desktop app - Used for discovering the Raspberry Pi and as an example of basic network TCP and UDP commands.
- Web app - A responsive web UI to control the Raspberry Pi audio through phones and web browsers. This is an easier alternative than building a from-scratch mobile app.
- Pi service - A TCP and UDP listener service that actually launches the audio files when requested.
The Desktop app provides basic control and discoverability of the Raspberry Pi. It was written in C++ with the Qt SDK and runs on Windows, Mac, and Desktop Linux.
Click "Find Pi", and the desktop app will send out a broadcast UDP packet and report the first one it finds. The other buttons become enabled allowing basic audio control.
If the Raspberry Pi was given a static IP address, then the desktop app is largely unnecessary. Control can be done through the web app.
The Web app is placed directly in /var/www
of the Raspberry Pi. It provides the same control as the desktop app. The difference is no software is needed to be installed -- only a web browser. The web app was built in PHP, JavaScript, and the Bootstrap framework so it will be responsive.
By making your web port available to the internet, the Pi Player is now an IoT-enabled device. Play audio at home. The back-end service can remain closed to the Internet because the PHP commands are connecting through 127.0.0.1.
The Pi listener service starts UDP and TCP listeners on port 15000. These listen for commands and actually invoke the audio player (mpg123) to start the MP3. The audio files must be MP3s located in the home directory. The service was written in C++ using the Qt SDK.
sudo apt-get install qt5-default build-essential mpg123
qmake && make
sudo daemon ./simpleTCPandUDPserver
Pi Player was heavily tested and developed using the open source project Packet Sender. The actual ASCII commands being sent are listed below. Send to ports 15000 for both UDP and TCP.
- Broadcast UDP: Find Units
- Unicast TCP:
- UnicastTCP: next
- UnicastTCP: stop
https://www.youtube.com/watch?v=4JXBG0TkA1g
This project is also detailed at hackster.io
All components are GPL v2 or Later. The "www" portion is based heavily on the Packet Sender web project if you'd prefer an MIT license.
This project is wholly owned and copyright © - @NagleCode - DanNagle.com