This tip will allow you to get the length of a wav, mid and AVI file.
Add a label and command button to your project, cut and paste the code below. This code will retrieve the length of the file in Minutes, seconds and milliseconds.
==================================================================
Option Explicit
Private Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Function GetMediaLength(FileName As String)
Dim MediaLength As Long
Dim RetString As String * 256
Dim CommandString As String
'open the media file
CommandString = "Open " & FileName & " alias MediaFile"
mciSendString CommandString, vbNullString, 0, 0&
'get the media file length
CommandString = "Set MediaFile time format milliseconds"
mciSendString CommandString, vbNullString, 0, 0&
CommandString = "Status MediaFile length"
mciSendString CommandString, RetString, Len(RetString), 0&
GetMediaLength = CLng(RetString)
'close the media file
CommandString = "Close MediaFile"
mciSendString CommandString, vbNullString, 0, 0&
End Function
Private Sub Command1_Click()
Dim Seconds, Minutes As Integer
Dim MilliSeconds As Long
Dim TotalTime
' replace "c:\your_wav_file.wav" with the path to your media file
MilliSeconds = GetMediaLength("c:\your_wav_file.wav")
' the function GetMediaLength return the media length in milliseconds,
' so we will calculate the total minutes and seconds
Seconds = Int(MilliSeconds / 1000) Mod 60
Minutes = Int(MilliSeconds / 60000)
MilliSeconds = MilliSeconds Mod 1000
TotalTime = Minutes & ": " & Seconds & ": " & MilliSeconds
Label1.Caption = TotalTime
End Sub