Process.Start for .WAV file

G

Guest

The following command plays a wave file and opens a media application:

Process.Start("C:\Windows\Media\tada.wav")

I would like to play a wav file without opening the default media player.
How do I do that?
 
I

Imran Koradia

You can P/Invoke on the PlaySound API:

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Integer, _
ByVal dwFlags As Integer) As Integer

Const SND_SYNC As Integer = &H0 ' play synchronously
Const SND_ASYNC As Integer = &H1 ' play asynchronously
Const SND_FILENAME As Integer = &H20000 ' lpszName is a file name
Const SND_PURGE As Integer = &H40 ' purge non-static events for task

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim RetStart As Integer = _
PlaySound("D:\WINDOWS\ring.wav", 0, SND_ASYNC Or SND_FILENAME)
Dim RetStop As Integer = _
PlaySound(Nothing, 0, SND_PURGE)
End Sub

Various other flag values and what they mean can be found here (where
PlaySound has been explained):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_playsound.asp


However, I'm not sure if one can play any other file types other than .wav
files with PlaySound. I could be wrong though - didn't have the time to test
it out.

hope that helps..
Imran.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top