Home > audio, mp3, RSS, threads, work in progress > C++ Audio player

C++ Audio player

As mentioned earlier I am currently developing an RSS win-forms application. One functionality that I recently have been working on consists of having podcast playback, in essence MP3 audio playback.

After the jump you will see a couple of screen-shots, showing the audio player both in design mode and in deployment mode, as well the library called libwmp3 that I have used to achieve the audio playback.

Design mode screen-shots:

As you can see the design is pretty much simple at the moment. The standard stop/play/pause/open buttons are fully functional. At the moment the application is able to load a MP3 file and display the current progress in the text box. The volume and progress UI are simply track bar controls. At the moment the progress track bar control is updated in real-time when a file is played, however I am still working on the seek function and volume control.

Displaying the file information such as the bitrate, title, track no and so on is also fully functional. The bitrate label is again updated in real-time, as a file is played since most audio files including those encoded in the MP3 format have a variable bit-rate.

Deployment mode screen-shots:

The following screen-shot was taken when I opened an MP3 file. As you can see the progress of the playback is updated via the text box control and track bar control.

Video showing the application playing back an audio file:

libwmp3 library

It is important to note that the libwmp3 library played a significant part in the audio playback feature, credit must be given to Zoran Cindori. It is well worth visiting the developers website to fully appreciate his work.

The library allows developers to easily allow playback into their application, and the library supports a number of programming languages from C to Visual Basic.

Background worker

The tricky part of this functionality of the RSS reader application, was updating the UI during play back. Since a different thread is needed to update UI, hence I incorporated a background thread control into the application. Thus exposing the controls following functions:

1. RunWorkerCompleted – invoked when the event and in this context play back is completed / cancelled.

2. ProgressChanged – invoked whenever we wish to update the UI, thus all UI updating is carried out in this function.

3. DoWork – the task to do this could be play/pause/stop etc.

4. CancelAsync – signal to cancel a currently running task, which interrupts the DoWork function.

Further work…

Work which still needs to be completed includes:

1. MP3 stream playback (stream track directly from a podcast)
2. Seek function
3. Set volume function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.