Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Audio Player

Here are examples of audio players you can use for inspiration:

  • foobar2000: An advanced freeware audio player for the Windows platform
  • MusicBee: The Ultimate Music Manager and Player

Here are resources that you can use to build your audio player:

00:00 GUI Project Ideas. In this section, we’re going to take a look at four projects for the desktop GUI: firstly, an audio player; secondly, an alarm tool; third, a file manager; and finally, an expense tracker.

00:18 First up, audio player. As someone who’s spent most of their life working with sound and music, I’d say that this is as important as text, if not even more so. I might be a little biased, however.

00:29 Unlike a record—where the audio is encoded in a physical manner, and then can be retrieved using an improvised tool, if needs be—digital audio files are complex and unplayable without a computer and the right software to turn the 0’s and 1’s back into audio.

00:44 An audio player project will play MP3 files and other digital audio formats. The GUI version is intended to emulate that now rarely seen physical item, the MP3 player, allowing playback on a Windows, Mac, or Linux computer.

00:59 The completed project will allow users to play audio files without any extra hardware, straight from their computer. Let’s take a look at a couple of examples of GUI audio players.

01:10 Here, you can see foobar2000. We’ve got a list of audio tracks lined up. We can play them,

01:20 control the volume—there’s a volume control, here—control the play position, skipping through the track to wherever we want. We’ve got pause and resume, we can go back to the beginning,

01:33 on to the next track, et cetera.

01:37 And here, you can see MusicBee in action. We can play this track. It’s got similar controls but they look a little more slick, in this case. Volume control, we’ve got a

01:49 ability to seek through the track wherever we want, we’ve got a standard play and pause control, and some visualization as well. Clearly, MusicBee has a slicker interface, but it’s a significantly larger amount of work to implement.

02:08 Let’s take a look at some of the technical areas you’ll need to address to create your audio player. Firstly, audio playback, using a library such as pygame, pymedia, or simpleaudio. You’ll need an engine to play back audio from Python.

02:23 pygame provides an easily-accessed audio engine, which has the ability to play back some compressed audio formats. .ogg is fully supported and some MP3 formats work without issue.

02:34 Other libraries such as pymedia and simple audio can also provide audio playback capability, which you can make use of as an audio back end for your application.

02:43 Secondly, interface. The interface of your audio player will be one of the most challenging areas of its implementation. While a basic audio player may only include buttons for stop and play, most users would expect a slider providing feedback of the current playtime and allowing control of the location within the file.

03:01 This will involve using more complex widgets within your chosen GUI framework. Playlists. Playlists are table stakes for most audio players, though storing this information may be most easily achieved using a database, rather than creating your own flat-file playlist format that you would then need to pass whenever you read a playlist.

03:20 This opens up the possibility of having an in-depth history function in the audio player, showing all the files that were played and when they were played.

03:29 Now, let’s take a look at some of the extra challenges you could take on when creating your audio player. First up, repeat and shuffle. Allowing a file to be played repeatedly using a toggle setting in the UI will typically involve the application monitoring the playback status of the audio and instigating playback again once that file has been completed.

03:49 Shuffle involves a randomization of a playlist, ensuring that the tracks in the playlist are all played before any are repeated. Playback speed changes. Some audio players have the ability to alter playback speed, whether for listening to podcasts that increase speed, or to slow down passages in music when learning technical sections.

04:08 This may be a function which is provided by the playback back end. DJ mode. A DJ mode will allow a continuous mixing of tracks in a playlist without any breaks between them. On a simple level, this would just be a crossfade between tracks for the short period of a few seconds where they overlap, but this may not be the most musical output.

04:28 It is possible to analyze the tempo of music tracks and then synchronize playback to get the sound of a human DJ mixing tracks together, but this would be a formidable task to achieve in this kind of project.

Become a Member to join the conversation.