Forum Moderators: open

Message Too Old, No Replies

Multimedia Support in .Net

How does .Net support multimedia functions

         

xgene

8:13 pm on May 29, 2002 (gmt 0)



I have not seen any multimedia support in .Net. Is there any currently, and if not, if/when will Microsoft include such support?

Xoc

8:24 pm on May 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There really isn't much built into the .NET Framework yet. This is a V1 product, so there are some holes in the .NET Framework. I imagine that Microsoft has something in the works on this, but as of yet, there are no classes in the framework to even play sound.

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.

Xoc

8:26 pm on May 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For example, here is the VB.NET code to play a wave file:

Dim snd As Sound = New Sound("c:\program files\netmeeting\ringin.wav")
snd.PlaySound()
snd.Dispose()

Where Sound is defined here:


Option Explicit On
Option Strict On

Public Class Sound
Implements IDisposable

Private disposed As Boolean = False

Private Structure MCI_WAVE_OPEN_PARMS
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

Private Structure MCI_PLAY_PARMS
Dim dwCallback As Integer
Dim dwFrom As Integer
Dim dwTo As Integer
End Structure

Private Structure MCI_GENERIC_PARMS
Dim dwCallback As Integer
End Structure

Private Declare Function mciSendCommandOpen Lib "winmm.dll" Alias _
"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

Private intDeviceID As Integer

Public Sub New(ByVal strFileName As String)
Dim mciOpenParms As MCI_WAVE_OPEN_PARMS
Dim lngRet As Integer

mciOpenParms.intDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO
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

Public Sub PlaySound()
Dim mciPlayParms As MCI_PLAY_PARMS
Dim lngRet As Integer

mciPlayParms.dwFrom = 0
lngRet = mciSendCommandPlay(intDeviceID, MCI_PLAY, MCI_WAIT Or MCI_FROM, _
mciPlayParms)
End Sub

Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Protected Overridable Overloads Sub Dispose(ByVal boolDisposing As Boolean)
Dim mciGenericParms As MCI_GENERIC_PARMS
Dim lngRet As Integer

If Not (Me.disposed) Then
lngRet = mciSendCommandClose(intDeviceID, MCI_CLOSE, MCI_WAIT, _
mciGenericParms)
End If
Me.disposed = True
End Sub

Protected Overrides Sub Finalize()
Dispose(False)
End Sub
End Class

xgene

8:43 pm on May 29, 2002 (gmt 0)



Oh, is that all? I though maybe it was hard ;-)