Build an MP3 Player

Building the Form

To begin, create a standard Visual Basic project. Next, select Projects | Components from the menu bar, and select Windows Media Player in the resulting dialog box. Click OK to add the component to your project. Now, select it from the Toolbox and drop it onto the default form. We'll use the component's built-in user interface for all the standard features like play, pause and stop. Resize the Media Player OCX as necessary, as shown in Figure B.

Figure B: We'll use the Windows Media Player for built-in features such as playing, pausing and stopping MP3 playback.

Adding controls

As we mentioned, in addition to playing MP3 files, we want the application to read and write certain information about each song--otherwise known as tag information. As an added bonus, we'll retrieve the file length and calculate the current playing time. To do so, however, we'll need to add a few more controls to our form. Use Figure A as a template for dropping in the appropriate controls. To display the MP3 tag information, add seven textboxes named as follows: txtTitle, txtArtist, txtAlbum, txtYear, txtComment and txtGenreCode. In addition, drop in a combobox called Combo1, two command buttons named cmdOpen and cmdWriteTage, a directory, drive and filelist box, a timer control and two labels named lblTotalTime and lblElapsedTime. All other controls can retain the standard VB assigned names.

Change the FileListBox's Pattern property to *.mp3 so that it displays only MP3 files. Finally, alter the label controls to read Total Time and Elapsed Time. Set the Timer control's Interval property to 60. If you want, you can add several additional labels beside the textboxes and name them as we have.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow