473,491 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Playing an audio file

Hi, is there a simple way to play a short audio file? Some of my users
would like to hear "There is a new order for your approval" when ever the
situation calls for it. Is this do-able?

Any help is greatly appreciated.
Nov 16 '05 #1
2 1984
This is easily doable if you use the windows API

First put this into the using section:
using System.Runtime.InteropServices;

Then define the funciton from the API:
[DllImport("winmm.dll")]
private static extern bool PlaySound( string lpszName, int
hModule, int dwFlags );

then provide a wrapper method for the API function:
private void playBtn_Click(object sender, System.EventArgs e)
{
String fileName = this.soundBox.Text;
PlaySound( fileName, 0, 1 );
}

The parameters of the windows API call are as follows:
lpszName - A string that specifies the sound to play.
hModule - Handle to the executable file that contains the
resource to be loaded. We pass in a NULL value instead.
dwFlags - Flags for playing the sound. We pass in SND_ASYNC.
The sound is played asynchronously and PlaySound returns immediately
after beginning the sound.

You can check out all this information here:
http://www.publicjoe.f9.co.uk/csharp/csharp17.html

Hope it helped,
Phil
On Thu, 22 Jul 2004 10:27:26 -0500, "Greg Smith" <gj*@umn.edu> wrote:
Hi, is there a simple way to play a short audio file? Some of my users
would like to hear "There is a new order for your approval" when ever the
situation calls for it. Is this do-able?

Any help is greatly appreciated.


Nov 16 '05 #2
There's an example here: http://www.codeproject.com/cs/media/PlaySounds1.asp
"Greg Smith" <gj*@umn.edu> wrote in message
news:uF**************@TK2MSFTNGP09.phx.gbl...
Hi, is there a simple way to play a short audio file? Some of my users
would like to hear "There is a new order for your approval" when ever the
situation calls for it. Is this do-able?

Any help is greatly appreciated.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2808
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
1
2662
by: laredotornado | last post by:
Hello, I want to play an audio file embedded on my page by clicking on an audio image and the page change to a new page. Is there a cross-browser Javascript way to do this? Right now the code I...
7
6414
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
4
4587
by: fAnSKyer/C# newbie | last post by:
I am using winmm.dll and I found that I can't just suspend it and resume it? What should I do? Any better idea? Should I use thread? and thread.suspend will work? Thanks
2
5037
by: gskrishnan | last post by:
I would like someone to help me with VB code for the following problem. I want to play a composed audio file of a certain beat cycle. A metronome file corresponding to the audio file beat cycle...
0
916
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
0
1089
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
1262
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
3361
by: Sobin Thomas | last post by:
Hi All, I want to play an audio file (wav)in my web page.I used the embed tag method.But it does'n work well in firefox.Is there any .NET class to play audio files?I already tried soundpalyer...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.