Skip to main content
Email Password   helpLost your password?

Sample Image - screenshot.jpg

Introduction

The tonysound.cs class gives you the ability to add Wav sound to your Windows forms. Simply include the tonysound.cs in your project folder. This is my first article, so please don't beat me up too bad.

Including the code in your form

Add the tonysound.cs file to your project. Then at the top of the calling form, for example, form1, type the following line to use the tonysound class.

using tonysound;

Once using tonysound; is included, then simply play the sound by calling:

Sound.Play(stringOfFilename,PlaySoundFlags.selectaflaghere );

Note: You can pass as many flags as you want, but if you're playing a file then you need to do something like I have in my code:

Sound.Play("sound.wav",PlaySoundFlags.SND_FILENAME);

The first parameter of Sound.Play is the filename. The filename can be the actual path, for example c:\\sound.wav, or it can simply be a Wav file that is in the same directory as the exe. The second is the flag for playing the sound. You can play a null sound to turn off the sound as follows:

Sound.Play(null,null);

NOTE: You must include either PlaySoundFlags.SND_FILENAME or PlaySoundFlags.SND_RESOURCE in order to actually play the song. The remaining flags are optional.

List of PlaySoundFlags and their use:

SND_SYNC //plays the sound after the event for example a button being pushed

SND_ASYNC //play sound as soon as event happens 

SND_NODEFAULT //don't play the default sound if the soundsource is not found 

SND_LOOP //play the wav over and over 

SND_NOSTOP //don't stop any currently playing sound 

SND_NOWAIT //don't wait if the sound driver is busy

SND_RESOURCE //indicates you are using a wav from a resource

SND_FILENAME //indicates you are using a wav from a file source

These are changes to my previous post, thanks to the suggestions.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralHow to play mp3 file instead of wav file Pin
Basma.a
22:12 2 Jan '09  
GeneralHELP Pin
sabsabsab
9:09 1 Jan '08  
GeneralAlternative - using sound recorder to play wave file programmatically Pin
daluu
15:46 19 Jul '07  
GeneralUse of tony sound library fails to work after compiling Pin
daluu
15:23 19 Jul '07  
GeneralDoes not play multiple sounds simultaneously Pin
jvelite
3:53 3 Jan '07  
GeneralOther than .wav files Pin
J.S.Lim
3:32 1 Jul '06  
GeneralThis sample only plays a unique sound Pin
Célio
4:07 23 Jun '06  
GeneralWaveform audio interface component for .NET Pin
AdamSlosarski
2:25 4 Nov '05  
GeneralHow about Record Audio? Pin
SuwitLam
7:54 17 Aug '05  
QuestionRe: How about Record Audio? Pin
Vash10
23:49 27 Aug '05  
AnswerRe: How about Record Audio? Pin
SuwitLam
8:15 28 Aug '05  
GeneralRe: How about Record Audio? Pin
Lwin Naing Oo
18:23 10 Sep '05  
GeneralPlease tell me what do these flags? Where do you find information about them? Pin
liubomir
20:38 4 Jun '05  
GeneralProcedure of using winmm.dll Pin
MohdYounisKhan
19:53 26 Oct '04  
GeneralWaveform audio interface component for .NET Pin
AdamSlosarski
2:25 4 Nov '05  
GeneralConsider these changes Pin
Mark Pitman
11:19 15 Apr '04  
GeneralRe: Consider these changes Pin
win32newb
12:38 15 Apr '04  
GeneralTonysound Class Pin
Daniel Stephen Rule
9:02 15 Apr '04  


Last Updated 14 Apr 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009