473,699 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to play sound in .net?

CM
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just
wonder how to play sound in .net?

Thanks!

CM
Nov 20 '05 #1
12 6599
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySou ndA" _

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just
wonder how to play sound in .net?

Thanks!

CM

Nov 20 '05 #2
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySou ndA" _

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just
wonder how to play sound in .net?

Thanks!

CM

Nov 20 '05 #3
CM
Thank you very much!
CM
Nov 20 '05 #4
CM
Thank you very much!
CM
Nov 20 '05 #5
CM
Hi, James:
It seems can only play .wav file. How to play .rm or other sound file?
Thanks!
CM

"james" <mo**********@n yc.rr.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias

"sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just wonder how to play sound in .net?

Thanks!

CM


Nov 20 '05 #6
CM
Hi, James:
It seems can only play .wav file. How to play .rm or other sound file?
Thanks!
CM

"james" <mo**********@n yc.rr.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias

"sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just wonder how to play sound in .net?

Thanks!

CM


Nov 20 '05 #7
rm needs it's own api I believe. sorry can't help there
"CM" <cm***@hotmail. com> wrote in message
news:uq******** ******@TK2MSFTN GP11.phx.gbl...
Hi, James:
It seems can only play .wav file. How to play .rm or other sound file?
Thanks!
CM

"james" <mo**********@n yc.rr.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias

"sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I

just wonder how to play sound in .net?

Thanks!

CM



Nov 20 '05 #8
rm needs it's own api I believe. sorry can't help there
"CM" <cm***@hotmail. com> wrote in message
news:uq******** ******@TK2MSFTN GP11.phx.gbl...
Hi, James:
It seems can only play .wav file. How to play .rm or other sound file?
Thanks!
CM

"james" <mo**********@n yc.rr.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias

"sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I

just wonder how to play sound in .net?

Thanks!

CM



Nov 20 '05 #9
MSN
I couldn't get this to work on web pages.
Does this work on web pages?
"james" <mo**********@n yc.rr.com> wrote in message
news:uC******** ******@tk2msftn gp13.phx.gbl...
try this:

'//Win32API
'//Both integer args and return were originally Longs - .NET Integer = vb6
Long
Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA " (ByVal lpszName As String, _
ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Friend Sub PlayAudio(ByVal FileName As String)
'//call win32api function to play audio (wav) file alert
Dim retval As Integer
retval = PlaySound(FileN ame, 0, 1)
'last param is SND_SYNC as integer
'value set to 0 plays sound Synchronously (waits until sound ends before
playing next)
'value set to 1 plays sound Asynchronously (does not wait to play next
sound)
End Sub

"CM" <cm***@hotmail. com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi,

I used to use the following code to play sound in VB6:

Public Declare Function sndPlaySound32 Lib "winmm.dll" Alias

"sndPlaySou ndA"
_

(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

call sndPlaySound32( "c:\WinNt\Media \ding.wav", 0)

However, .net don't recognize "call", and generate a syntax error. I just wonder how to play sound in .net?

Thanks!

CM


Nov 20 '05 #10

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

Similar topics

22
2554
by: The Road To Utopia | last post by:
Here's one for the trolls...a common jibe from them is setting up audio/video hardware under linux. Ok, true story: at work today, someone asked me if I could tell him why his XP Home would play the video from a DVD but not the audio. He had been searching for an answer for days on support.microsoft.com but found none. I suggested Google and Gateway. Gateway had nothing, but sure enough, search for *XP DVD no sound* on Google and...
6
4047
by: Andrew Poulos | last post by:
As a follow on to the 'fun' I had with IE I'm now trying to play sounds using an Object tag (no Embed) in MZ. Sadly whenever 'playButton' gets clicked MZ says that "audObj.Play is not a function": window.onload = function() { var audObj = document.createElement("object"); audObj.setAttribute("id", "objmedia"); audObj.setAttribute("type","audio/x-aiff"); audObj.setAttribute("data","media/aif_sample.aif");
1
4298
by: Ron Provost | last post by:
Hello, I'm developing a piece of software to assist illiteraate adults to learn to read. I'm trying to figure out how, if possible, to make audio playback asynchrnous but still controllable. I'm using python 2.4 with pymedia on XP. I started out with the example in the tutorials section of the pymedia website. The pymedia docs imply to me that playback using Output's play() method should already be asynchronous and controllable. I...
2
4591
by: NB | last post by:
I've done a thorough search, but could not find any posts If I store a sound file within the mdb, How do I play it (in a form event, for example) I can save it to a temp folder and call the Windows API to play it. But that doesn't look very clean. I guess there must be a way to directly play that sound without first extracting it.
22
3757
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and type in c:\MyApp\MyHelp\Help1.wav, Windows Media Player tries unsuccessfully to play the wav file. It err's saying ClassFactory cannot supply the requested class. But WMP has no problem at all playing c:\windows\system32\ ALSNDMGR.WAV. That goes...
5
7189
by: Dennis C. Drumm | last post by:
I have a windows form configured as a fixed dialog I'm using as a custom MessageBox (has some additional buttons). How do I get it to play the standard windows sounds when envoked and can I insert the standard MessageBox icons into this dialog? Thanks, Dennis
1
8002
by: Lam | last post by:
how can I play sound file in a .aspx page written in C#? I try to use the code like the following. But whenI call the play function play("sound.wav", this.SND_ASYNC) my computer give out "be" sound instead playing the file (same code works fine in a windows application written in c# , that mean there is nothing wrong with my sound card.) thanks ----------------------------------------------------------------------------...
3
10637
by: Jared | last post by:
I'm using the first code sample below to play WAV files stored as embedded resources. For some reason I *occasionally* get scratching and crackling. I'm using a couple WAVs that ship with Windows, and they play fine outside of my app. This code works, but has the random "scratching" problem: private static void PlayResource(string audioRes) { // Get the resource into a stream
5
2154
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to play the sound. It works perfectly well in Windows XP, but when I move my application to a Vista machine, the sound does not play... I used a debug statement to confirm that the files are seen in the code but somehow it does not play... If I use...
26
3893
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are almost no posts from the last 3 years: http://groups.google.com/group/comp.lang.javascript/search?group=comp.lang.javascript&q=how+to+play+a+sound+with+Javascript&qt_g=Search+this+group Even after sorting by date, there don't appear any...
0
8691
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
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9038
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
8920
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
7755
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6536
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
5877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4378
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2012
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.