C# for Beginners: Make Your Own MP3 Player, Free

C# is so ridiculously simple that even a beginner can make an MP3 player in no time at all using the free Express edition of Visual C#. I've used the 2010 edition for this tutorial, but other versions will probably work fine too --- 2008 for instance.



OK, it'll help a lot if you spend a few weeks learning basic syntax first, but even if you don't know any C# at all you will probably still be able to follow this tutorial. Just cut and paste stuff.

I've structured this tutorial in question and answer form, so that you can test your knowledge as you go along. See how far you can get without looking at the answers!

The MP3 player we create will be very no-frills, but you can use it as the basis of more elaborate projects.

Let's get started.

Step 1. Create a New C# project


Once you've downloaded the free Express edition of Visual Studio C#, create a new project and change the name of the main form to something nice.


Step 2. Add a label and three buttons to the form.


Rename the buttons to "open", "play" and "stop".


Step 3. Create a music player class


Create a new class. Import "winmm.dll" and add the prototype for the mciSendString function.

Add methods to open a file, start play and stop play.



Step 4: Add handlers to your buttons to control your music player.





Step 5: Enjoy the music.



That's it. If the above instructions don't work and you're tearing your hair out .... errrm, I'm sorry! They should work. If your project doesn't compile, don't worry, you've just mistyped something somewhere.

If it compiles and runs but you hear no sound, something is badly deranged and I don't know what. Can you play mp3 files OK with Windows Media Player?

Did you add in the button and dialog handlers by double-clicking them? You must do this; if you just paste in the code, your click events won't hook up to your handlers.

Your new mp3 player is certainly rough around the edges, but that's where the fun comes in. You can use it as the basis of your own mp3 player; refine it, sort out any bugs and drawbacks, add features to your heart's content.

More larks?



If you found this page useful, please consider clicking one of the buttons below to tell others about it!

I used to mainly use C++, Perl and Java, but about a year ago I tried C# and was pleasantly surprised. It's really child's play compared to C++.

If you're a beginner, it'll seem confusing at first, but you'll progress quickly. Good luck!