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 for every platform.
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.
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.
A non-functioning demo of the web app is running at piplayer.naglecode.com
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.
Initial setup requires:
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: play
- UnicastTCP: next
- UnicastTCP: stop