01-03-2026, 06:46 PM
(This post was last modified: 01-05-2026, 01:19 AM by DerVVulfman.)
The MCISendString Multimedia Class
Version: 1.0
Based upon work by Mark Thesing (July 18, 2002)
Version: 1.0
Based upon work by Mark Thesing (July 18, 2002)
Introduction
Permits the loading, playback, and various other actions on a multimedia file.
Since its original creation in 2002, the ability to present video content in a picturebox object has been added. Along with that, more multimedia file extensions are now recognized.
Do note, the class will only load and play one multimedia file at a time. In order for a project to play multiple files, multiple instances of this class need to be defined.
LOOPING:
Using the MCISendstring system, there is always a millisecond break as the MCISendstring attempts to loop back to the start, even with the built-in repeat function.
Features
- Supports playback of the following Audio formats: aiff, amr, flac, m4a, midi, mp2, mp3, wav, wma
- Supports playback of the following Video formats: avi, mpg, mpeg, mp4, m4v, asf, wmv
- Allows custom loop position
Limitations
- Video footage does not have stretch-to-fit nor any resizing
- Avi footage 'still' has no audio playback
- Geared for Visual Basic 6
Code
Code
Code:
' ==============================================================================
' ** The MCISendString Multimedia Class
' ------------------------------------------------------------------------------
' by DerVVulfman
' version 1.0
' 01-03-2026 (mm/dd/yyyy)
' Based upon work by Mark Thesing (July 18, 2002)
' ==============================================================================
'
' INTRODUCTION:
' -------------
'
' Permits the loading, playback, and various other actions on a multimedia file.
'
' Since its original creation in 2002, the ability to present video content in a
' picturebox object has been added. Along with that, more multimedia file exten-
' tions are now recognized.
'
' Do note, the class will only load and play one multimedia file at a time. In
' order for a project to play multiple files, multiple instances of this class
' need to be defined.
'
' LOOPING: Using the MCISendstring system, there is always a millisecond break
' as the MCISendstring attempts to loop back to the start, even with
' the built-in repeat function.
'
'
' ==============================================================================
'
' CLASS INSTALLATION:
' -------------------
'
' * In the form where used, define this class before any other action.
' -- Example: Private clsMM As New Class_MSS
'
' * If you need two or more files playing, define multiple instances like so.
' -- Example: Private clsMMOne As New Class_MSS
' Private clsMMTwo As New Class_MSS
'
' The 'clsMM' (or like) will direct you to commands within this class.
' -- Example: clsMM.mmPlay
'
' * Ensure the class instance (or instances) removed from memory upon exit.
' It is also recommended to end any multimedia playback being executed.
' This is done within the form's "Form_Unload" private subroutine.
' -- Example: clsIni.mmStop
' Set clsIni = Nothing
' End
'
'
' ==============================================================================
'
' MULTIMEDIA FORMATS:
' -------------------
'
' Audio: aiff, amr, flac, m4a, midi, mp2, mp3, wav, wma
' Video: avi, mpg, mpeg, mp4, m4v, asf, wmv
'
' * Amr format not recommended; playback sounds low quality
' * Avi format has no audio playback
'
' * Formerly, only wav, mid, mp3, avi, mpg and mpeg were supported.
'
'
' ==============================================================================
'
' METHODS:
' --------
'
' CLOSE: Closes the currently loaded file.
' * SYNTAX: <classname>.mmClose
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' OPEN: Opens the desired file. Optionally sets a window for video display.
' * SYNTAX: <classname>.mmOpen filename [, object]
' * filename: The full filename (with path) to be loaded for playback.
' * object: (Optional) The hwnd supported form object for video use.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' PAUSE: Pauses the file or resumes playback.
' * SYNTAX: <classname>.mmPause
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' PLAY: Plays the loaded file. Optionally accepts whether the file loops.
' * SYNTAX: <classname>.mmPlay [, repeat]
' * repeat: (Optional) True/False if the multimedia file loops.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' SEEK: Sets current playback to a specific position within the file.
' * SYNTAX: <classname>.mmSeek location
' * location: The point within the file (in millisecond) to advance
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' SEEK INCREMENT: Sets playback to a position based on 1/1000th of its length.
' * SYNTAX: <classname>.mmSeekIncr value
' * value: (Range 0-1000) The point based on 1/100th of its length.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' STOP: Ends playback of the loaded file. Sets the reader to the file's end.
' * SYNTAX: <classname>.mmStop
'
' ------------------------------------------------------------------------------
'
'
' ------------------------------------------------------------------------------
'
' PROPERTIES:
' -----------
'
' FILENAME: Retrieves the name of the currently loaded file.
' * SYNTAX: returned = <classname>.Filename
' * returned: (String) The name of the currently loaded file
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' FILENAME: Opens a specified filename. Does not define a window like OPEN.
' * SYNTAX: <classname>.Filename filename
' * filename: The full filename (with path) to be loaded for playback.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' LENGTH: Retrieves the length/duration of the current file in milliseconds.
' * SYNTAX: returned = <classname>.Length
' * returned: (Single) The file's playback duration in milliseconds
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' PAUSED: Retrieves if media playback was temporarily halted.
' * SYNTAX: returned = <classname>.Paused
' * returned: (Boolean) Returns True/False on pause status
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' PERCENT: Retrieves the percent of the file played to one decimal position.
' * SYNTAX: returned = <classname>.percent
' * returned: (Single: Range of 0.0-100.0) Current amount played.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' POSITION: Retrieves the current playback position of the current file.
' * SYNTAX: returned = <classname>.Position
' * returned: The full filename (with path) to be loaded for playback.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' POSITION: (as Seek) Sets playback to a specified position of the current file.
' * SYNTAX: <classname>.Position location
' * location: The point within the file (in millisecond) to advance.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' TO_BEGIN: Retrives (in milliseconds) where media playback will begin or resume
' * SYNTAX: returned = <classname>.To_Begin
' * returned: (Single) The position where media playback starts.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' TO_BEGIN: Defines where playback begins, or where to return if set to repeat.
' * SYNTAX: <classname>.To_Begin location
' * location: The point within the file (in millisecond) to start.
' NOTE: It must be called 'after' [To_Reloop] if both are used together.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' TO_END: Retrives (in milliseconds) where media playback is set to end.
' * SYNTAX: returned = <classname>.To_End
' * returned: (Single) The position where media playback ends.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' TO_END: Defines where playback ends if not at the end of the current file.
' * SYNTAX: <classname>.To_End location
' * location: The point within the file (in millisecond) to end.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' TO_RELOOP: Defines where playback ends if not at the end of the current file.
' * SYNTAX: <classname>.To_ReLoop location
' * location: The point in the file (in millisecond) to restart loop.
' NOTE: If used in tandem with [To_Begin], it must be called first.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' VOLUME: Gets the playback volume.
' * SYNTAX: returned = <classname>.Volume
' * returned: (Long) The volume amplitude (generally 0-100)
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' VOLUME: Sets the playback volume.
' * SYNTAX: <classname>.Volume amplitude
' * amplitude: The volume of audio playback.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' VOLUME LEFT: Sets the playback volume for the left volume channel
' * SYNTAX: <classname>.VolumeL amplitude
' * amplitude: The volume of the left channel playback.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' VOLUME RIGHT: Sets the playback volume for the right volume channel.
' * SYNTAX: <classname>.VolumeR amplitude
' * amplitude: The volume of the right channel playback.
'
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' ------------------------------------------------------------------------------
'
'
' ==============================================================================
Option Explicit
' API Function Declarations
' ==============================================================================
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
' Private Variable Declarations
' ==============================================================================
Private strAlias As String ' Mmedia resource name
Private strFileName As String ' Current filename
Private strFrom As String ' Defined Playback start
Private strTo As String ' Defined Playback end
' --------------------------------------------------------------------------
Private sngLength As Single ' Playback length
Private sngIncrement As Single ' Length divided by 1000
Private sngPosition As Single ' Current position
Private sngToSkip As Single ' Loop flourish skip
Private sngSeekFrom As Single ' Loop starting point
Private sngSeekTo As Single ' Loop ending point
' --------------------------------------------------------------------------
Private strStatus As String ' Current playing status
Private bPlaying As Boolean ' If file is playing
Private bPaused As Boolean ' If paused or not
Private bRepeat As Boolean ' If loops
' --------------------------------------------------------------------------
Private lngVolume As Long ' Current volume
Private lngVolumeL As Long ' (above) Left Volume
Private lngVolumeR As Long ' (above) Right Volume
' ==============================================================================
' = CLASS FUNCTIONS ============================================================
' ==============================================================================
' The Initialization routine
'===============================================================================
Private Sub Class_Initialize()
'
strAlias = "" ' Set empty Alias name
strFileName = "" ' Set empty filename
bPlaying = False ' No playing at start
bPaused = False ' No pause at start
sngToSkip = 0 ' Clear loop points
sngSeekFrom = 0 ' Clear loop points
sngSeekTo = 0 ' Clear loop points
lngVolume = 0 ' Clear volume values
lngVolumeL = 0 ' Clear volume values
lngVolumeR = 0 ' Clear volume values
'
End Sub
' ==============================================================================
' = GENERAL FUNCTIONS ==========================================================
' ==============================================================================
' CLOSE FILE
' Close the currently open multimedia file
' ==============================================================================
Public Sub mmClose()
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
If strAlias = "" Then Exit Sub ' Exit if no file open
'
strCmd = "Close " & strAlias ' Make MCI Close Command
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
strAlias = "" ' Clear opened file
strFileName = "" ' Clear filename
bPlaying = False ' Flag not playing
'
End Sub
' OPEN FILE
' Open the specified multimedia file and close any others that may be open
' ==============================================================================
Public Sub mmOpen(ByVal strTheFile As String, _
Optional ByVal objPic As Object = Nothing)
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim strLen As String * 255 ' Gets the file length
Dim strType As String ' Holds the file type
Dim intLength As Integer ' Returned data's length
Dim bVideo As Boolean ' Defined video window
'
' Initialize subroutine constant
Const WS_CHILD As Long = &H40000000 ' Define child window
'
bPlaying = False ' Flag not playing
bPaused = False ' Turn off paused flag
'
If strAlias <> "" Then mmClose ' Close if previous open
'
' Determine playback mode based on file extension
' --------------------------------------------------------------------------
Select Case UCase(Right(strTheFile, 4)) ' Branch on extension
' -- AUDIO FORMATS -----------------------------------------------------
Case ".WAV" ' For Wav extension
strType = "Waveaudio" ' ... assume wave audio
bVideo = False ' ... set no-video usage
Case ".MID" ' For mid extension
strType = "Sequencer" ' ... assume sequencer
bVideo = False ' ... set no-video usage
Case "AIFF", ".AMR", "FLAC" ' For AIFF, AMR and FLAC
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = False ' ... set no-video usage
Case ".M4A", ".MP2", ".MP3" ' For MP2/3 extensions
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = False ' ... set no-video usage
Case ".WMA" ' For flaky WMAs
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = False ' ... set no-video usage
' -- VIDEO FORMATS -----------------------------------------------------
Case ".AVI" ' For Avi extension
strType = "AviVideo" ' ... assume avi video
bVideo = True ' ... set video usage
Case "MPEG", ".MPG", ".MP4" ' For MPG, MPEG or MP4
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = True ' ... set video usage
Case ".ASF", ".M4V" ' For ASF or M4V
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = True ' ... set video usage
Case ".WMV" ' For flaky WMVs
strType = "MPEGVideo" ' ... Mpeg system use
bVideo = True ' ... set video usage
' -- NO VALID FORMAT FOUND ---------------------------------------------
Case Else ' -- otherwise --
Exit Sub ' Exit if unrecognized
End Select
' --------------------------------------------------------------------------
'
strAlias = Right(strTheFile, 3) & Minute(Now) ' Make unique alias name
'
If InStr(strTheFile, " ") Then ' If filename has spaces
strTheFile = Chr(34) & strTheFile & Chr(34) ' ... wrap in quotes
End If
'
If pvt_ObjExist(objPic) = False Then ' If no picture object
bVideo = False ' Force no video usage
End If
'
' Create the Open MCISendString command
' --------------------------------------------------------------------------
strCmd = "Open " & strTheFile ' Make MCI Open command
strCmd = strCmd & " alias " & strAlias ' Include alias name
If bVideo = True Then
strCmd = strCmd & " parent " ' Set target window use
strCmd = strCmd & CStr(objPic.hWnd) ' Set actual target
strCmd = strCmd & " style " & CStr(WS_CHILD) ' Set as child window
Else
strCmd = strCmd & " Type " & strType ' Add audio type
End If
strCmd = strCmd & " WAIT" ' Force wait till play
' --------------------------------------------------------------------------
'
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
' Ensure file set to start position and increments
' --------------------------------------------------------------------------
strCmd = "Status " & strAlias & " length" ' Make MCI Length cmd
lngReturn = mciSendString(strCmd, strLen, 255, 0) ' Pass MCI command
intLength = InStr(strLen, Chr(0)) ' Get end of length
sngLength = Val(Left(strLen, intLength - 1)) ' Set to class variable
sngIncrement = sngLength / 1000
'
' Define loop start and end defaults
' --------------------------------------------------------------------------
sngToSkip = 0 ' Loop flourish point
sngSeekFrom = 0 ' Loop starting point
sngSeekTo = sngLength ' Loop ending point
' --------------------------------------------------------------------------
'
' Ensure file set to start position
' --------------------------------------------------------------------------
strCmd = "Seek " & strAlias & " to 0" ' Make MCI Seek Command
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
' --------------------------------------------------------------------------
'
End Sub
' PAUSE PLAYBACK
' Pause playback of the file
' ==============================================================================
Public Sub mmPause()
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
If strAlias = "" Then Exit Sub ' Exit if no file open
'
If bPlaying = False Then Exit Sub ' Exit if not playing
'
If bPaused = False Then ' If already paused
bPaused = True ' ... set flag n pause
strCmd = "Pause " & strAlias ' Make MCI Pause Command
Else
bPaused = False ' ... set flag n play
strCmd = "Resume " & strAlias ' Make MCI Resume Cmnd
End If
'
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
End Sub
' PLAY FILE
' Plays the currently open file from the current position
' ==============================================================================
Public Sub mmPlay()
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim strTo2 As String
'
If strAlias = "" Then Exit Sub ' Exit if no file open
'
bPlaying = True ' Flag IS playing
bPaused = False ' Playing, not paused
'
strCmd = "Play " & strAlias ' Make MCI Play Command
strFrom = " from " & Trim(Str(sngSeekFrom)) ' Set start position
strCmd = strCmd & strFrom ' Add to Play command
'
If pvt_LoopCheck = False Then ' If no custom loops
If bRepeat = True Then ' If set to repeat
strCmd = strCmd & " Repeat" ' Add repeat to command
End If
End If
'
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
If bRepeat = False Then Exit Sub ' Exit if no repeating
If pvt_LoopCheck = False Then Exit Sub ' Exit if no loop spot
'
pvt_LoopExecute ' Perform repeat loop
'
End Sub
' SEEK TO PLAYBACK LOCATION
' Seek a specific position within the file
' ==============================================================================
Public Sub mmSeek(ByVal sngPosition As Single)
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
strCmd = "Seek " & strAlias ' Make MCI Seek Command
strCmd = strCmd & " to " & Trim(Str(sngPosition)) ' Define seek position
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
End Sub
' SEEK TO LOCATION ON INCREMENTAL VALUE
' Seek a specific position within the file based on value
' ==============================================================================
Public Sub mmSeekIncr(ByVal intIncrement As Integer)
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim sngPosition As Long
'
If intIncrement < 0 Then Exit Sub ' Exit if out of range
If intIncrement > 1000 Then Exit Sub ' Exit if out of range
'
sngPosition = intIncrement * sngIncrement ' Math based on range
'
strCmd = "Seek " & strAlias ' Make MCI Seek Command
strCmd = strCmd & " to " & Trim(Str(sngPosition)) ' Define seek position
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
If bPlaying = False Then Exit Sub ' Exit if not playing
If bPaused = True Then Exit Sub ' Exit if paused
'
strCmd = "Play " & strAlias ' Make MCI Play Command
'
If pvt_LoopCheck = False Then ' If no custom loops
If bRepeat = True Then ' If set to repeat
strCmd = strCmd & " Repeat" ' Add repeat to command
End If
End If
'
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
End Sub
' STOP PLAYBACK
' Stop using a file totally. Running or not.
' ==============================================================================
Public Sub mmStop()
' ---------------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim sngLength As Single ' Sets playback length
'
If strAlias = "" Then Exit Sub ' Exit if no file open
'
bPlaying = False ' Flag not playing
'
strCmd = "Stop " & strAlias ' Make MCI Stop Command
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
sngLength = Length ' Get playback length
'
strCmd = "Seek " & strAlias ' Make MCI Seek Command
strCmd = strCmd & " to " & Trim(Str(sngLength)) ' Define seek end
lngReturn = mciSendString(strCmd, "", 0, 0) ' Pass MCI command
'
End Sub
' ==============================================================================
' = PROPERTY SETTINGS ==========================================================
' ==============================================================================
' FILENAME (GET)
' Returns the object FileName Property
' ==============================================================================
Public Property Get Filename() As String
' ----------------------------------------------------------------
'
Filename = strFileName ' Get value from class
'
End Property
' FILENAME (LET)
' Sets the objects FileName property.
' ==============================================================================
Public Property Let Filename(ByVal New_FileName As String)
' ----------------------------------------------------------------
' Sets the objects FileName property. This also implies
' that you also want to open the file so control is passed
' to the mmOpen method
'
strFileName = New_FileName
mmOpen New_FileName
'
End Property
' PLAYBACK LENGTH (GET)
' Returns the length of the file, the value acquired when file was opened
' ==============================================================================
Public Property Get Length() As Single
' ----------------------------------------------------------------
'
If strAlias = "" Then ' If no file is open
Length = 0 ' Set zero length
Exit Property ' and Exit
End If
'
Length = sngLength ' Get value from class
'
End Property
' PAUSED (GET)
' Returns the status of being paused (using in-class variables)
' ==============================================================================
Public Property Get Paused() As Boolean
' ----------------------------------------------------------------
'
Paused = bPaused ' Get value from class
'
End Property
' PERCENT (GET)
' Returns the relative position in the media relative to its size in 0-100 range
' ==============================================================================
Public Property Get Percent() As Single
' ----------------------------------------------------------------
'
' Initialize property variables
Dim fLength As Single ' Media file duration
Dim fPosition As Single ' Current play position
Dim fPercent As Single ' Percent value as float
Dim iPercent As Integer ' Integer in deciseconds
'
' Initialize function variables
If strAlias = "" Then ' If no file is open
Percent = 0 ' Set zero length
Exit Property ' and Exit
End If
'
fLength = Length ' Get media duration
fPosition = Position ' Get current position
'
fPercent = fPosition / fLength ' Get increment
iPercent = fPercent * 1000 ' Get range 0-1000
Percent = iPercent / 10 ' Set to range 0.0-100.0
'
End Property
' PLAYBACK POSITION (GET)
' Returns the current position in the file if a file is open
' ==============================================================================
Public Property Get Position() As Single
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim strPos As String * 255 ' Returned pos buffer
Dim intLength As Integer ' Returned data's length
'
If strAlias = "" Then ' If no file is open
Position = 0 ' Set zero position
Exit Property ' and Exit
End If
'
strCmd = "Status " & strAlias & " position" ' Make MCI Position cmd
lngReturn = mciSendString(strCmd, strPos, 255, 0) ' Pass MCI command
'
intLength = InStr(strPos, Chr(0)) ' Get end of position
Position = Val(Left(strPos, intLength - 1)) ' Set to function
'
End Property
' PLAYBACK LENGTH (LET)
' Set the position property by seeking
' ==============================================================================
Public Property Let Position(ByVal New_Position As Single)
' ----------------------------------------------------------------
'
sngPosition = New_Position ' Get value from class
mmSeek New_Position ' Pass into mmSeek
'
End Property
' REPEAT (GET)
' Returns the objects Repeat property
' ==============================================================================
Public Property Get Repeat() As Boolean
' ----------------------------------------------------------------
'
Repeat = bRepeat ' Get value from class
'
End Property
' REPEAT (LET)
' Sets the value of the object Repeat property
' ==============================================================================
Public Property Let Repeat(ByVal New_Repeat As Boolean)
' ----------------------------------------------------------------
'
bRepeat = New_Repeat ' Set into class value
'
End Property
' PLAYBACK STATUS (GET)
' Return the playback/record status of the current file
' ==============================================================================
Public Property Get Status() As String
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim strStat As String * 255 ' Returned status buffer
Dim intLength As Integer ' Returned data's length
'
If strAlias = "" Then Exit Property ' Exit if no file open
'
strCmd = "Status " & strAlias & " mode" ' Make MCI Status cmd
lngReturn = mciSendString(strCmd, strStat, 255, 0) ' Pass MCI command
'
intLength = InStr(strStat, Chr(0)) ' Get end of status
Status = Left(strStat, intLength - 1) ' Set to function
'
End Property
' PLAYBACK BEGIN LOOP (GET)
' Retrieves the position (in milliseconds) where the media playback begins
' ==============================================================================
Public Property Get To_Begin() As Single
' ----------------------------------------------------------------
'
To_Begin = sngSeekFrom ' Get value from class
'
End Property
' PLAYBACK BEGIN LOOP (LET)
' Sets the position(in milliseconds) media playback is to begin or resume
' ==============================================================================
Public Property Let To_Begin(ByVal New_Begin As Single)
' ----------------------------------------------------------------
'
If New_Begin < 0 Then Exit Property ' Exit if invalid point
If New_Begin > sngLength Then Exit Property ' Exit if invalid point
If New_Begin >= sngToSkip Then Exit Property ' Exit if past To_Skip
If New_Begin >= sngSeekTo Then Exit Property ' Exit if past the end
' --------------------------------------------------------------------------
If New_Begin = sngSeekFrom Then Exit Property ' Exit if already set
' --------------------------------------------------------------------------
sngSeekFrom = New_Begin ' Set playback start
'
End Property
' PLAYBACK BEGIN LOOP (GET)
' Retrieves (in milliseconds) the start position of a loop.
' ==============================================================================
Public Property Get To_End() As Single
' ----------------------------------------------------------------
'
To_End = sngSeekTo ' Get value from class
'
End Property
' PLAYBACK BEGIN LOOP (LET)
' Sets the position(in milliseconds) media playback ends, to possibly loop back
' ==============================================================================
Public Property Let To_End(ByVal New_End As Single)
' ----------------------------------------------------------------
'
If New_End < 0 Then Exit Property ' Exit if invalid point
If New_End > sngLength Then Exit Property ' Exit if invalid point
If New_End <= sngToSkip Then Exit Property ' Exit if before To_Skip
If New_End <= sngSeekFrom Then Exit Property ' Exit if before start
' --------------------------------------------------------------------------
If New_End = sngSeekTo Then Exit Property ' Exit if already set
' --------------------------------------------------------------------------
sngSeekTo = New_End ' Set playback end
'
End Property
' PLAYBACK RELOOP TO (Let)
' Sets the position(in milliseconds) playback is to resume if it began earlier
' ==============================================================================
Public Property Let To_ReLoop(ByVal New_To_Skip As Single)
' ----------------------------------------------------------------
'
If New_To_Skip < 0 Then Exit Property ' Exit if invalid position
If New_To_Skip > sngLength Then Exit Property ' Exit if invalid position
If New_To_Skip >= sngSeekTo Then Exit Property ' Exit if past loop end
' --------------------------------------------------------------------------
If New_To_Skip = sngToSkip Then Exit Property ' Exit if already set
' --------------------------------------------------------------------------
sngToSkip = New_To_Skip ' Set To_Skip Point
sngSeekFrom = 0 ' Reset start point
'
End Property
' PLAYBACK VOLUME (GET)
' Return the playback volume of the current file
' ==============================================================================
Public Property Get Volume() As Long
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
Dim strStat As String * 255 ' Returned status buffer
Dim intLength As Integer ' Returned data's length
'
If strAlias = "" Then ' If no file is open
Volume = 0 ' Set zero volume
Exit Property ' and Exit
End If
'
strCmd = "Status " & strAlias & " volume" ' Make MCI Status cmd
lngReturn = mciSendString(strCmd, strStat, 255, 0) ' Pass MCI command
'
intLength = InStr(strStat, Chr(0)) ' Get end of status
Volume = Val(Left(strStat, intLength - 1)) / 10 ' Set to function
'
End Property
' PLAYBACK VOLUME (LET)
' Sets the playback volume
' ==============================================================================
Public Property Let Volume(ByVal New_Volume As Long)
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
If strAlias = "" Then Exit Property ' Exit if no file open
'
If New_Volume < 0 Or New_Volume > 100 Then ' If volume is invalid
Exit Property ' Exit
End If
'
lngVolume = New_Volume * 10 ' Set the volume
'
strCmd = "setaudio " & strAlias ' Make MCI command
strCmd = strCmd & " Volume to " ' Define for volume
strCmd = strCmd & lngVolume ' Define volume level
lngReturn = mciSendString(strCmd, "", 0, 0&) ' Pass MCI command
'
End Property
' PLAYBACK LEFT VOLUME LET)
' Sets the playback volume for the left channel
' ==============================================================================
Public Property Let VolumeL(ByVal New_Volume As Integer)
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
If strAlias = "" Then Exit Property ' Exit if no file open
'
If New_Volume < 0 Or New_Volume > 100 Then ' If volume is invalid
Exit Property ' Exit
End If
'
lngVolumeL = New_Volume * 10 ' Set the volume
'
strCmd = "setaudio " & strAlias ' Make MCI command
strCmd = strCmd & " left volume to " ' Define left volume
strCmd = strCmd & lngVolumeL ' Define volume level
lngReturn = mciSendString(strCmd, "", 0, 0&) ' Pass MCI command
'
End Property
' PLAYBACK RIGHT VOLUME LET)
' Sets the playback volume for the right channel
' ==============================================================================
Public Property Let VolumeR(ByVal New_Volume As Integer)
' ----------------------------------------------------------------
'
' Initialize function variables
Dim lngReturn As Long ' mciSendString return
Dim strCmd As String ' Sets the MCI commands
'
If strAlias = "" Then Exit Property ' Exit if no file open
'
If New_Volume < 0 Or New_Volume > 100 Then ' If volume is invalid
Exit Property ' Exit
End If
'
lngVolumeR = New_Volume * 10 ' Set the volume
'
strCmd = "setaudio " & strAlias ' Make MCI command
strCmd = strCmd & " right volume to " ' Define left volume
strCmd = strCmd & lngVolumeR ' Define volume level
lngReturn = mciSendString(strCmd, "", 0, 0&) ' Pass MCI command
'
End Property
' ==============================================================================
' = PRIVATE FUNCTIONS ==========================================================
' ==============================================================================
' CHECK FOR CUSTOM LOOP
' Runs constantly when envoked to repeat media based on custom start/stop points
' ==============================================================================
Private Function pvt_LoopCheck() As Boolean
' ----------------------------------------------------------------
'
pvt_LoopCheck = False ' Set function false
If sngSeekTo <> sngLength Then pvt_LoopCheck = True ' Set true if loop end
If sngSeekFrom <> 0 Then pvt_LoopCheck = True ' Set true if start
If sngToSkip <> 0 Then pvt_LoopCheck = True ' Set true if To_Skip
'
End Function
' EXECUTE CUSTOM LOOP
' Runs constantly when envoked to repeat media based on custom start/stop points
' ==============================================================================
Private Sub pvt_LoopExecute()
' ----------------------------------------------------------------
'
If bRepeat = False Then Exit Sub ' Exit if repeat is OFF
'
Do While bPlaying = True ' Loop only if playing
DoEvents ' Permit other functions
If bRepeat = False Then Exit Do ' Exit if repeat is OFF
If Position >= sngSeekTo Then ' If loop end point found
If sngToSkip > 0 Then ' -- if To_Skip exists
sngSeekFrom = sngToSkip ' -- ... replace start
End If
mmPlay ' Re-start play
End If
Loop
'
End Sub
' OBJECT EXISTS?
' Returns whether a defined object exists or not
' ==============================================================================
Private Function pvt_ObjExist(objParm As Object) As Boolean
' ----------------------------------------------------------------
'
pvt_ObjExist = IIf(objParm Is Nothing, False, True)
'
End Function
Class_MSS.zip (Size: 6.93 KB / Downloads: 7)
Instructions
Plenty... in the code itself.
FAQ
The original code which this was based had no set-up for video playback, no pointing to any hwnd supported objects. This was one of the main additions I included
Credits and Thanks
Thanks to Mark Thesing who wrote the base code in 2002
Terms and Conditions
Use as you see fit. No requirements other than due credit for both Mr. Thesing and myself.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links

![[Image: QrnbKlx.jpg]](https://i.imgur.com/QrnbKlx.jpg)
![[Image: sGz1ErF.png]](https://i.imgur.com/sGz1ErF.png)
![[Image: liM4ikn.png]](https://i.imgur.com/liM4ikn.png)
![[Image: fdzKgZA.png]](https://i.imgur.com/fdzKgZA.png)
![[Image: sj0H81z.png]](https://i.imgur.com/sj0H81z.png)
![[Image: QL7oRau.png]](https://i.imgur.com/QL7oRau.png)
![[Image: uSqjY09.png]](https://i.imgur.com/uSqjY09.png)
![[Image: GAA3qE9.png]](https://i.imgur.com/GAA3qE9.png)
![[Image: 2Hmnx1G.png]](https://i.imgur.com/2Hmnx1G.png)
![[Image: BwtNdKw.png%5B]](https://i.imgur.com/BwtNdKw.png%5B)