473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Long delay playing sound for Win API

Using the Win API to play a sound with the code below in my Windows Form
application. I get a huge delay (seems like application is hanging) just
prior to the sound being played each time. Is this something to do with
unmanaged code? Is there any way to fix the delay and speed the process up?

Thanks,

Dennis

using System.Runtime.InteropServices;

[DllImport("winmm.dll")]

public static extern int sndPlaySound(string lpszSoundName, int uFlags);

sndPlaySound("Windows XP Exclamation.wav", 0x001);


Nov 15 '05 #1
2 3722
Dennis:

I've used this a fair amount on both the Desktop and Pocket PC and haven't
noticed any performance degradation.

Mine implementation is slightly different, but I don't think that's the
cause---I had just read that you should use constants instead...

Define two constants...
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;

Define PlaySOund ass

public static extern bool PlaySound(string pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Windows XP Exclamation.wav",
SND_FILENAME|SND_ASYNC);

See if this doesn't make a difference.

BTW, I got the code originally from John Paul Mueller's .NET Framework
Solutions....I don't want to take credit for his stuff. He does mention
that you should use the COnstants, so maybe that's a possible issue.

Not sure...but maybe this helps.

Cheers,

BIll
"Dennis C. Drumm" <de*******@primacode.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Using the Win API to play a sound with the code below in my Windows Form
application. I get a huge delay (seems like application is hanging) just
prior to the sound being played each time. Is this something to do with
unmanaged code? Is there any way to fix the delay and speed the process up?
Thanks,

Dennis

using System.Runtime.InteropServices;

[DllImport("winmm.dll")]

public static extern int sndPlaySound(string lpszSoundName, int uFlags);

sndPlaySound("Windows XP Exclamation.wav", 0x001);

Nov 15 '05 #2
Actually, I was using the public const int's as well, I just was trying to
save space on my post. I tried it in a clean test app and didn't experience
the dalay, so its something to do with my windows form app. I should have
tried that before.

Dennis
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Dennis:

I've used this a fair amount on both the Desktop and Pocket PC and haven't
noticed any performance degradation.

Mine implementation is slightly different, but I don't think that's the
cause---I had just read that you should use constants instead...

Define two constants...
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;

Define PlaySOund ass

public static extern bool PlaySound(string pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Windows XP Exclamation.wav",
SND_FILENAME|SND_ASYNC);

See if this doesn't make a difference.

BTW, I got the code originally from John Paul Mueller's .NET Framework
Solutions....I don't want to take credit for his stuff. He does mention
that you should use the COnstants, so maybe that's a possible issue.

Not sure...but maybe this helps.

Cheers,

BIll
"Dennis C. Drumm" <de*******@primacode.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Using the Win API to play a sound with the code below in my Windows Form
application. I get a huge delay (seems like application is hanging) just
prior to the sound being played each time. Is this something to do with
unmanaged code? Is there any way to fix the delay and speed the process

up?

Thanks,

Dennis

using System.Runtime.InteropServices;

[DllImport("winmm.dll")]

public static extern int sndPlaySound(string lpszSoundName, int uFlags);

sndPlaySound("Windows XP Exclamation.wav", 0x001);


Nov 15 '05 #3

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

Similar topics

0
by: didifouke | last post by:
Hi, I try to sample and playback speech using snack. My idea is to have a socket based server that plays back the sound and a client that samples the input from the sound card and sends it to...
5
by: Johnny M | last post by:
I use the following code to play WAV files from Access. Is there a method to play MP3 files from an Access event or control.: '***************************************************** Option Compare...
5
by: DCC-700 | last post by:
I am using ASP.Net with VB on the 1.1 Framework running on Win XP Pro. I am trying to gauge the time it takes to sort a datagrid using different code sets. But when I am debugging the page there...
3
by: nj609eagle | last post by:
Recently and without warning, a report that I was using in my VB.NET 2003 application started to take 10 minutes to load. It also take thisamount of time to open in the deisgner. I'm using a...
1
by: pkoziejko | last post by:
Hi! I have implemented psychoacustic Johnson model for wav files, and now I need to play data after modification. Now I have only playing *.wav using and PlaySound( "wav_file.wav",...
0
by: bdtmike | last post by:
I'm using VS2005 and creating a VB.Net Winforms app. The app uses a couple of web services. For some reason, when I start the app, there is a 30 second delay when VB invokes its first web service....
1
by: oops | last post by:
I've had no luck getting 2 sound files to start at the same time. the second one to start is delayed by about 3/4 of a second. Also would also prefer to start another clip a given point when one of...
4
by: Benzerari | last post by:
Hi All; Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound...
1
by: desturrr | last post by:
Hello all, I have small sized mp3 files that i can play via Java using JLayerPlayer that takes the address of mp3 files , JLayerPlayer objects can be played creating threads and starting. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.