Example application using the radiodan gem
This application is alpha software. We're releasing it to start a discusion about what a radio prototyping platform could be.
Open an issue if you'd like help getting started.
To run:
$ foreman start
More detailed instructions coming soon.
- Listen to BBC radio stations
- Web app to control the radio
- "Avoid track" button to avoid tracks you don't like
- Physical interface
The physical interface exists in it's own repository.
The app consists of Radiodan middlewares.
lib/middleware/radio_controller.rb
This listens for events triggered on the player and causes changes on the Radiodan::Playlist object. There's only a single Playlist object that's used.
lib/middleware/preferences.rb
Remembers state such as volume and current station in a file and reads it on start-up.
lib/middleware/faye_web_server.rb
This loads a web server, the Faye messaging server and the Web App (see below)
A web app is mounted on port 3000, so will be available on an URL such as http://raspberrypi.local:3000
.
lib/web_app.rb
contains the HTTP interface for controlling the radio and displaying basic state information such as the volume and current station. The web app simple triggers events on the player rather than changing anything directly. e.g. to change the volume the :change_volume
event would be fired with the desired volume value.
Javascript is used to listen and display now playing messages and to change radio stations and volume without relaoding the web page. This uses the Faye. The web app interface is in lib/views/
and the Javascript and CSS is in lib/public/
.
Converts messages received over the Faye interface into player events understood by the Radio Controller middleware.
NowPlayingClient
class in lib/now_playing_client.rb
subscribes to now playing updates using the MQTT prototocl. Messages received are broadcast using Faye to the web app and other parts of the app.
Using the NowPlayingClient to avoid tracks. When the :avoid, :track
event is triggered and Now Playing information is available for the track, this middleware works out how long of the track is left to play
The sounds/birdsong.mp3
is from http://www.freesfx.co.uk
See COPYING file.