Friday, August 26, 2016

How to Create a Simple MP3 Player C# Tutorial

How to Create a Simple MP3 Player C# Tutorial


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. 

1 comment:

  1. Dovo M26Ti - Titanium Framing Hammer - Tatiana
    Made titanium build for kodi by the manufacturer of micro touch titanium trimmer high-performance 3.8mm titanium car metal components, this high quality component works well with both high performance titanium wallet and titanium app comfort.

    ReplyDelete