CodeItBetter Programming Another VB Programming Blog

How to Retrieve The Length Of WAV, AVI And MIDI Files

Posted on August 14, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'MultiMedia - How to Retrieve The Length Of WAV, AVI And MIDI Files

Option Explicit
 
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
 
Public Function GetMediaLength(ByVal sFileName As String) As String
    Dim Seconds As Integer, Minutes As Integer
    Dim MediaLength As Long
    Dim RetString As String * 256
    Dim CommandString As String
    'open the media file
    CommandString = "Open " & sFileName & " 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&
    MediaLength = CLng(RetString)
    'close the media file
    CommandString = "Close MediaFile"
    mciSendString CommandString, vbNullString, 0, 0&
 
    'the media length returns in milliseconds, so we need calculate the total minutes and seconds
    Seconds = Int(MediaLength / 1000) Mod 60
    Minutes = Int(MediaLength / 60000)
    MediaLength = MediaLength Mod 1000
    GetMediaLength = Minutes & ":" & Seconds & ":" & MediaLength
End Function
 
'How can I call this function:
'Call MsgBox(GetMediaLength("C:\WINDOWS\clock.avi"), vbInformation, App.Title)
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.