Forum Moderators: open
However, the Windows API is still available and fully accessible from .NET. So while it isn't any easier than it use to be, it also isn't any harder, and can certainly be done.
Dim snd As Sound = New Sound("c:\program files\netmeeting\ringin.wav")
snd.PlaySound()
snd.Dispose()
Where Sound is defined here:
Public Class Sound Private disposed As Boolean = False Private Structure MCI_WAVE_OPEN_PARMS Private Structure MCI_PLAY_PARMS Private Structure MCI_GENERIC_PARMS Private Declare Function mciSendCommandOpen Lib "winmm.dll" Alias _ Private intDeviceID As Integer Public Sub New(ByVal strFileName As String) mciOpenParms.intDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO Public Sub PlaySound() mciPlayParms.dwFrom = 0 Public Overloads Sub Dispose() Implements IDisposable.Dispose Protected Overridable Overloads Sub Dispose(ByVal boolDisposing As Boolean) If Not (Me.disposed) Then Protected Overrides Sub Finalize()
Option Explicit On
Option Strict On
Implements IDisposable
Dim dwCallback As Integer
Dim wDeviceID As Integer
Dim intDeviceType As Short
Dim intDeviceOrdinal As Short
Dim lpstrElementName As String
Dim lpstrAlias As String
Dim dwBufferSeconds As Integer
End Structure
Dim dwCallback As Integer
Dim dwFrom As Integer
Dim dwTo As Integer
End Structure
Dim dwCallback As Integer
End Structure
"mciSendCommandA" (ByVal wDeviceID As Integer, ByVal uMessage As Integer, _
ByVal dwParam1 As Integer, ByRef dwParam2 As MCI_WAVE_OPEN_PARMS) As Integer
Private Declare Function mciSendCommandPlay Lib "winmm.dll" Alias _
"mciSendCommandA" (ByVal wDeviceID As Integer, ByVal uMessage As Integer, _
ByVal dwParam1 As Integer, ByRef dwParam2 As MCI_PLAY_PARMS) As Integer
Private Declare Function mciSendCommandClose Lib "winmm.dll" Alias _
"mciSendCommandA" (ByVal wDeviceID As Integer, ByVal uMessage As Integer, _
ByVal dwParam1 As Integer, ByRef dwParam2 As MCI_GENERIC_PARMS) As Integer
Private Const MCI_OPEN As Short = &H803S
Private Const MCI_OPEN_ELEMENT As Integer = &H200
Private Const MCI_DEVTYPE_WAVEFORM_AUDIO As Short = 522
Private Const MCI_OPEN_TYPE_ID As Integer = &H1000
Private Const MCI_PLAY As Short = &H806S
Private Const MCI_FROM As Integer = &H4
Private Const MCI_CLOSE As Short = &H804S
Private Const MCI_WAIT As Integer = &H2
Dim mciOpenParms As MCI_WAVE_OPEN_PARMS
Dim lngRet As Integer
mciOpenParms.intDeviceOrdinal = 0
mciOpenParms.lpstrElementName = strFileName
mciOpenParms.dwBufferSeconds = 30
lngRet = mciSendCommandOpen(0, MCI_OPEN, MCI_WAIT Or MCI_OPEN_TYPE_ID _
Or MCI_OPEN_ELEMENT, mciOpenParms)
intDeviceID = mciOpenParms.wDeviceID
End Sub
Dim mciPlayParms As MCI_PLAY_PARMS
Dim lngRet As Integer
lngRet = mciSendCommandPlay(intDeviceID, MCI_PLAY, MCI_WAIT Or MCI_FROM, _
mciPlayParms)
End Sub
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Dim mciGenericParms As MCI_GENERIC_PARMS
Dim lngRet As Integer
lngRet = mciSendCommandClose(intDeviceID, MCI_CLOSE, MCI_WAIT, _
mciGenericParms)
End If
Me.disposed = True
End Sub
Dispose(False)
End Sub
End Class