473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("winm m.dll")]

public static extern int sndPlaySound(st ring lpszSoundName, int uFlags);

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


Nov 15 '05 #1
2 3743
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(strin g pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Wind ows XP Exclamation.wav ",
SND_FILENAME|SN D_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*******@prim acode.com> wrote in message
news:%2******** ********@tk2msf tngp13.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("winm m.dll")]

public static extern int sndPlaySound(st ring lpszSoundName, int uFlags);

sndPlaySound("W indows 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********@com cast.nospam.net > wrote in message
news:eo******** ******@TK2MSFTN GP09.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(strin g pszSound, int hmod, int
fdwSound);

then the call would be PlaySound("Wind ows XP Exclamation.wav ",
SND_FILENAME|SN D_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*******@prim acode.com> wrote in message
news:%2******** ********@tk2msf tngp13.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("winm m.dll")]

public static extern int sndPlaySound(st ring lpszSoundName, int uFlags);

sndPlaySound("W indows 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
1597
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 the server using the socket connection. On the snack page there is a tutorial showing a socket server implementation using tcl: http://www.speech.kth.se/snack/tutorial.html
5
3784
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 Database Option Explicit Declare Function sndplaysound Lib "WINMM.DLL" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long Dim soundName As String Dim WFlags As Integer
5
2081
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 is a long delay before hitting breakpoint in page load. When I initially load the page I hit the breakpoint right away. Then I click on a Sort header in a datagrid, and it takes about 1:45 before the breakpoint (first statement in Page Load) is...
3
2626
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 ADO.NET XML file as the datasource, so there is no network traffic. Loking at the task manager, my CPU is low, and the memory isn't changing. I have two laptops and anyone off my network can open this report up without the long delay.
1
2679
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", IntPtr.Zero,0x00020000 | 0x0001) function.
0
1701
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. After that, the response time on subsequent calls is nearly intantaneous. As an example, If I'm debugging and press <F5I'll get the 30 second delay on first invocation, then it's fast after that. If I stop the program and restart (F5), I get...
1
1264
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 the others is still playing. If anyone knows of a link to a similar issue could you please spare the time to post it? come on, you've read this far ;) thanks in advance!!
4
5069
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 or music which is: OLE.DoVerb (vbOLEPrimary) But the one to stop or interupt the sound I could not find it. Please let know
1
2478
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 problem is when i have for example 9 sounds and i want it them to play in consecutively , so i put them in for loop like: for(int i=1;i<mainNotaList.size()+1;i++) { neyBox1.arrangeNeyImage(mainNotaList.get(i-1)); ...
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.