Now that you’ve seen how easy it is to play a WAV file, why not extend the system to include AVI files? This means that you’ll need to use a different function—MCISendString instead of SndPlaySnd—but little else changes. The following procedure will play either a WAV file or an AVI file by checking its extension. This means that we can now use sound or video for our multimedia help system without having to make any changes to the infrastructure. By using the MCI, it’s fairly simple to extend the code to play any type of multimedia file that is supported by the MCI.
Public Sub PlayHelp(ByVal niMMID As String)
' This subroutine plays a multimedia help file. It will select
' the type of call to the MCI depending on the file retrieved.
Dim sMMFile As String ' File returned from the resource file
Dim nIndex As Integer ' Saves the period location
Dim sExtension As String ' The file extension
Dim lReturn As Long ' The return details from the MCI
Static bAviOpen As Boolean ' Is AVI playing?
Static bWavOpen As Boolean ' Is WAV playing?
' Get the multimedia filename from the resource file using
' the multimedia ID passed in.
sMMFile = App.Path & LoadResString(niMMID)
' Now we can check for the file type--WAV or AVI--and
' play the help file indicated from the resource file.
' Check the extension.
nIndex = InStr(sMMFile, ".")
sExtension = Mid$(sMMFile, nIndex + 1)
' Play the multimedia file, depending on its extension.
Select Case LCase$(sExtension)
' WAV files.
Case "wav"
' If a WAV file is open, then...
If bWavOpen Then
' Stop it, and close it.
lReturn = WinmciSendString("Stop WaveFile", "", 0, 0)
lReturn = WinmciSendString("Close WaveFile", "", 0, 0)
End If
' Set the WAV file open flag to true.
bWavOpen = True
' Open it.
lReturn = WinmciSendString("Open " & sMMFile & _
" alias WaveFile type WaveAudio", "", 0, 0)
' Play it (NoWAIT).
lReturn = WinmciSendString("Play WaveFile", "", 0, 0)
' AVI files.
Case "avi"
' If an AVI file is open, then...
If bAviOpen Then
' Stop it, and close it.
lReturn = WinmciSendString("Stop AviFile", "", 0, 0)
lReturn = WinmciSendString("Close AviFile", "", 0, 0)
End If
' Set the AVI file open flag to True.
bAviOpen = True
' Open it.
lReturn = WinmciSendString("Open " & sMMFile & _
" alias AviFile type AviVideo", "", 0, 0)
' Play it (NoWAIT) in full screen mode.
lReturn = WinmciSendString(_
"Play AviFile fullscreen ", "", 0, 0)
End Select
mdiShow.bPuSpoken = False ' Turn help off.
mdiShow.MousePointer = vbDefault 'Reset the mouse pointer.
End Sub
As with the previous procedure, the path and file details are first retrieved from the resource file. To determine what type of multimedia file to play by means of the MCI, the file extension is extracted. If a file of the type indicated by the extension is currently playing, the file is stopped, and the selected file is then played using MCISendString.