Touchscreen audio controller for presentation sound

The controls Function

The controls function is identical to the background class's controls function starting on line 58 with a few more buttons added. The only difference is on line 155, where self.state is checked. Similar to how background will draw the play button dim or bright depending on whether it is playing or not, playlist changes the button label to be "PLAY" or "PAUSE" accordingly.

The command Function(s)

command is a simple dispatcher function that looks at cmd and calls the appropriate class function (lines 195-200). The next and prev functions (lines 201-221) fadeout (lines 203, 214) the currently playing track, increment (line 204) or decrement (line 215) the trackIndex, and then start playback with the new track (same as lines 145-151).

volup and voldown (lines 223-233) are identical to their background class equivalents with the addition of the last time self.volumeChange = True. This flag lets the class know that the volume should be redrawn on the screen. drawVolume (lines 235-236) returns a PyGame surface with the class's current volume level.

tick (lines 238-242) is called once a second by the main loop. If the sound is currently playing (line 239), then I increment self.currentTime. Line 241 renders the time remaining in the track and returns the surface.

Buy this article as PDF

Express-Checkout as PDF

Pages: 2

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content