Click here to Skip to main content
15,887,596 members
Articles / Programming Languages / C#
Article

.NET Audio buttons with professional look

Rate me:
Please Sign up or sign in to vote.
1.35/5 (25 votes)
10 Aug 20032 min read 66K   1.4K   26   5
.NET buttons that used for audio functions - write your own control

Sample Image - AudioButtons.jpg

Introduction

When I wrote a program to play audio files (.wav, mp3) I need add some buttons for playing audio files. Unfortunately, .NET doesn’t have such buttons. As part of study on how to write my own controls, I create these audio buttons including Play, Pause, Rewind, Forward, Stop, ToEnd, ToStart. User can use them just as they are using the standard buttons supplied by VS .NET.

Using the code

Here is one example of how to use the code: <o:p>

1.      Use the project in your own solution: Download the source code, which is a project itself. Unzipped it into your solution folder (this would be better, but you can save them wherever you like) In your Solution Explorer in VS .NET, right click the solution and choose “Add”  and “existing project…”. Choose AudioControls project from where ever you unzipped it, then click Open.<o:p>

2.      Add the AudioControls project as a reference to your own project: Right click your own project other than AudioControls project in Solution Explorer, choose “Add reference …” Then click the tab “Projects”, choose the project the click “Select”, then “OK”.<o:p>

3.      Add AudioButtons into your toolbox: At design mode, click your “Toolbox” and choose one of the tab (say My User Controls or whichever group you want the audiobuttons appear in) Right click the toolbox and choose “Add/Removing Items….” In “.NET Framework Components” tab click “Browse…”, in the new window browse for “AudioButtons.dll”, (normally should be under \bin\debug folder) then click “Open”<o:p>

4.      Now you can use AudioButtons just as you use standard buttons from VS .NET. In Properties window, you can find new properties “Audio Button”: ButtonType (ToStart, Rewind, Play, Pause, Stop, Forward, ToEnd), IconLocation and IconSize. They are self-explaining.<o:p>

Further development

There are several properties could be added to the audio buttons, such as colors, gradient changing modes etc.  You can easily add them by following the example of the code (property part). Hope these buttons are of some useful for you either in using them or in writing your own controls.<o:p>

Thanks

Great thanks to Georgi Atanasov, whose article “Owner-draw button” were firstly studied before I started to write my own controls. Great thanks also goes to Carlos H. Perez and his UtilityLibrary.<o:p>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMute and Click event Pin
Saied Javadi10-Jul-06 5:30
Saied Javadi10-Jul-06 5:30 
QuestionHow to play audio files? Pin
crystalice543296113-Aug-03 5:31
crystalice543296113-Aug-03 5:31 
AnswerRe: How to play audio files? Pin
above13-Aug-03 6:03
above13-Aug-03 6:03 
AnswerRe: How to play audio files? Pin
Ryan_Roberts13-Aug-03 6:04
Ryan_Roberts13-Aug-03 6:04 
AnswerRe: How to play audio files? Pin
dallyanzi13-Aug-03 6:53
dallyanzi13-Aug-03 6:53 
crystalicetpmc wrote:
Can you expose the code that about how to play audio files with C#?
Thank you very much.

test


For low-level audio file manipulation, there are two ways to do it in .NET. One is DirectSound and another is using Interop.

1. if you are dealing with short files, then DirectSound would be an ideal solution for you. In its examples, there are very detailed ones showing step by step how to use directsound. But if you are dealing with huge files (like several hundred Mb), you then have to stream the file in DirectSound, there isn't any example showing how to do that. But you can following the example in C++. NET.

2. Using Interop. There are several good articles explains very well how to playing audio files. One of them is from Ianier: A low-level audio player in C#
Another is nBASS, which is a wrapper of BASS. Both the above projects have plenty codes.

I have chosen nBASS, and my project is finishing for the Alfa version testing soon. I will post them on to codeproject and keep updating them. At that time, there will be a lot more information about it from my website too.

If you still need more information, either leave a message here or drop an email to me directly.
Hope this could help.



_________________
When you know a thing, to recognize that you know it, and when you do not know a thing, to recognize that you do not know it. That is knowledge. ---- CONFUCIUS (Chinese philosopher 551 BC - 478 BC)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.