how to play a wave file in c# 
Author Message
 how to play a wave file in c#

with this declaration you can easely play wave files in C#,
but the problem is that the function seems to be modal, this means that
your program is wait until the wave files has been played.

[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long
dwFlags);

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Wed, 24 Nov 2004 21:33:34 GMT  
 how to play a wave file in c#
Should be able to do this in its own thread so control returns ?  I'd like
to know how.

best, Bill Woodruff
dotScience


Quote:

> with this declaration you can easely play wave files in c#,
> but the problem is that the function seems to be modal, this means that
> your program is wait until the wave files has been played.

> [DllImport("winmm.dll")]
> public static extern long PlaySound(String lpszName, long hModule, long
> dwFlags);

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Thu, 25 Nov 2004 22:15:06 GMT  
 how to play a wave file in c#

I don't understand what you meen,
but i'll give an exemple of using playsound.
(i forgot to following line to)

using System.Runtime.InteropServices;
  //this line you need to add to de head of the form file

[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long
dwFlags);
 //this two line you need to add to the declaration part of your form

private void button1_Click(object sender, System.EventArgs e)
{
    //Playsound ("c:\windows\media\tada.wav",0,0);
    // this line would not work
    // because c# can't work with the "\" part of strings
    //sow you need to get the filename with a opendialog or some othre
way
    //exemple.
    opendia.ShowDialog();
    PlaySound (opendia.FileName,0,0);

Quote:
}

Sow i hope this helps you,
cu

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Thu, 25 Nov 2004 23:17:28 GMT  
 how to play a wave file in c#
Just ONE correctin which I focus on - Ronny, go though the C# Language
specification once more :-)

--
Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)


Quote:
>     //Playsound ("c:\windows\media\tada.wav",0,0);
>     // this line would not work
>     // because c# can't work with the "\" part of strings
>     //sow you need to get the filename with a opendialog or some othre way
>     //exemple.

No, this line will not work because you made one mistake here - "\" is a
special symbol for entering special chars. It needs to me masked, or special
char processing needs to be turned of. C# can very well work with "\" in
source code. Let me explain:

(a) Masking "\":

Quote:
>     Playsound ("c:\\windows\\media\\tada.wav",0,0);

Simple: Just double it. "\\" is the special symbol for "\". Other special
symbols are "\r" "\n" (together: char(13), Char (10),. CRLF.

(b) turning off "\" processing:


at all, so "\r\n" are stored as exactly this.

Just as a note.

Thomas



Thu, 25 Nov 2004 23:32:40 GMT  
 how to play a wave file in c#
yes, of course i knew that,
but i thought it was easyer to explain with a opendialog.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Fri, 26 Nov 2004 00:37:29 GMT  
 how to play a wave file in c#
Bill, I'm not an expert with PlaySound, but the flags parameter has this
value:

SND_SYNC - Synchronous playback of a sound event. PlaySound returns after
the sound event completes.

I read this to mean that the routine will by default play the sound
asynchronously. Maybe someone can confirm this?

-glenn-


Quote:
> Should be able to do this in its own thread so control returns ?  I'd like
> to know how.

> best, Bill Woodruff
> dotScience



> > with this declaration you can easely play wave files in c#,
> > but the problem is that the function seems to be modal, this means that
> > your program is wait until the wave files has been played.

> > [DllImport("winmm.dll")]
> > public static extern long PlaySound(String lpszName, long hModule, long
> > dwFlags);

> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!



Fri, 26 Nov 2004 23:02:39 GMT  
 how to play a wave file in c#
D'oh! Don't know how I missed this in the PlaySound documentation, but there
is also a flag SND_ASYNC which plays the sound asynchronously.

So there shouldn't be any need to create a thread manually to play the sound
asynchronously.

-glenn-


Quote:
> Bill, I'm not an expert with PlaySound, but the flags parameter has this
> value:

> SND_SYNC - Synchronous playback of a sound event. PlaySound returns after
> the sound event completes.

> I read this to mean that the routine will by default play the sound
> asynchronously. Maybe someone can confirm this?

> -glenn-



> > Should be able to do this in its own thread so control returns ?  I'd
like
> > to know how.

> > best, Bill Woodruff
> > dotScience



> > > with this declaration you can easely play wave files in c#,
> > > but the problem is that the function seems to be modal, this means
that
> > > your program is wait until the wave files has been played.

> > > [DllImport("winmm.dll")]
> > > public static extern long PlaySound(String lpszName, long hModule,
long
> > > dwFlags);

> > > *** Sent via Developersdex http://www.developersdex.com ***
> > > Don't just participate in USENET...get rewarded for it!



Fri, 26 Nov 2004 23:07:41 GMT  
 how to play a wave file in c#

Hy, :-)
i found a way to play wave/mide files (non-modal)
of course with directx (8)
it's using a visualbasic libary, but it works,

contact me for the source code

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 27 Nov 2004 02:22:16 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. The playing of Wave files

2. How can I play a wave file?

3. How to play a wave file

4. How to play a wave file

5. how to play a wave file in c#

6. check the waveform data when playing the wave file.

7. How to play a wave file on the phone ?

8. playing wave files in visual c

9. Playing wave files on Sun unix

10. Playing wave files on Sun Solaris

11. Playing a wave file from a resource

12. playing wave files

 

 
Powered by phpBB® Forum Software