بازيابي مدت زمان پخش فايلهاي WAV ،AVI و MIDI در VB:
با استفاده از يک مثال به شما نشان خواهيم داد که چگونه مي توانيد در ويژوال بيسيک مدت زمان پخش يک فايل صوتي از نوع WAV ،AVI و يا MIDI را بدست بياوريد. اين تکنيک براي ساخت مدياپلير در VB کاربرد دارد و بطور کلي برنامه هايي که به نوعي با اجراي فايلهاي صوتي در ارتباط است.
براي اين منظور از:
1- يک Module ايجاد کرده و کد زير را در آن بنويسيد:
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
2- در بخش کد فرم، کدهاي زير را وارد نماييد.
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 Form_Load()
Dim Seconds, Minutes As Integer
Dim MilliSeconds As Long
' replace "c:\my_media_file.wav" with the path to your media file
MilliSeconds = GetMediaLength("c:\my_media_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
MsgBox (TotalTime)
End Sub
توجه داشته باشيد که ما در اين مثال از يک فايل صوتي بنام my_media_file.wav استفاده کرديم که شما بايستي آنرا تغيير داده و مسير فايل صوتي بر روي کامپيوترتان را مشخص نماييد.
منبع خبر: ايگولد سيتي