Module dShow
Public DSAudio As QuartzTypeLib.IBasicAudio
Public DSVideo As QuartzTypeLib.IBasicVideo
Public DSWindow As QuartzTypeLib.IVideoWindow
Public DSControl As QuartzTypeLib.IMediaControl
Public DSPos As QuartzTypeLib.IMediaPosition
Public Const WS_VISIBLE As Integer = &H10000000
Sub DS_OpenFile(ByRef Filename As String, ByRef rectTop As Short, ByRef rectLeft As Short, ByRef rectWidth As Short, ByRef rectHeight As Short, ByRef FhWnd As Integer, Optional ByRef fullScreen As Boolean = False)
On Error Resume Next
'Puliamo prima di caricare un nuovo file
Call DS_termina()
DSControl = New QuartzTypeLib.FilgraphManager 'crea il controllo
Call DSControl.RenderFile(Filename) 'carica il file
'crea il controllo del volume
DSAudio = DSControl
DSAudio.Volume = 0 'regola il volume come normale
DSAudio.Balance = 0 'centra l'audio
DSWindow = DSControl 'crea l'oggetto che contiene il video(se presente
DSWindow.WindowStyle = &H10000000 'finestra visibile
DSWindow.Top = rectTop 'dimensioni del controllo
DSWindow.Left = rectLeft
DSWindow.Width = rectWidth
DSWindow.Height = rectHeight
DSWindow.Owner = FhWnd
DSWindow.FullScreenMode = fullScreen
DSPos = DSControl 'crea il controllo della posizione
DSPos.Rate = 1
End Sub
Public Sub DS_Play()
'Esegui il play
DSPos.CurrentPosition = 0
Call DSControl.Run()
End Sub
Public Sub DS_Pause()
'pausa
Call DSControl.Pause()
End Sub
Public Sub DS_Riprendi()
'riprendi da una pausa
DSControl.Run()
End Sub
Public Sub DS_Stop()
'Stop
Call DSControl.Stop()
DSPos.CurrentPosition = 0
End Sub
Public Sub DS_SetRate(ByRef velocità As Double)
If velocità <= 0 Then velocità = 0.1
'regola la velocità
DSPos.Rate = velocità
End Sub
Public Function DS_GetLen() As Double
'ricevi la durata del file
DS_GetLen = DSPos.Duration
End Function
Public Function DS_GetPosition() As Double
'ricevi la posizione
DS_GetPosition = DSPos.CurrentPosition
End Function
Public Sub DS_SetPosition(ByRef posizione As Double)
'modifica la posizione del filmato
If posizione > DSPos.Duration Then posizione = DSPos.Duration
DSPos.CurrentPosition = posizione
End Sub
Public Function DS_GetVolume() As Integer
'ricevi il volume
DS_GetVolume = DSAudio.Volume
End Function
Public Sub DS_SetVolume(ByRef Volume As Integer)
'il volume va da 0 a -10000
If Volume > 0 Then Volume = 0
If Volume < -10000 Then Volume = -10000
DSAudio.Volume = Volume
End Sub
Public Function DS_GetBalance() As Integer
'ricevi il balance
DS_GetBalance = DSAudio.Balance
End Function
Public Sub DS_SetBalance(ByRef Balance As Integer)
Dim newBalance As New Object
Dim nBalance As New Object
'va da -10000 a +10000
If Balance < -10000 Then Balance = -10000
If nBalance > 10000 Then Balance = 10000
DSAudio.Balance = newBalance
End Sub
Public Sub DS_termina()
On Error Resume Next
'fermiamo il file se sta già in esecuzione
DSControl.Stop()
DSWindow.Owner = 0
'distruggi tutto
DSAudio = Nothing
DSVideo = Nothing
DSControl = Nothing
DSWindow = Nothing
DSPos = Nothing
End Sub
End Module