Getting fileinfo of an mp3 is no problem but I have discovered that it is more complex when I try to get file duration of video files (.avi,.mpg) etc.
My code listed below uses a timer. In order for me to get a video duration value, I must actually play the file in axwindowsmediaplayer1 for one second. This seems not practical.
I have seen many examples on the internet in C# that read video metadata without need to play/load the file. Why are there no examples in vb.net of this? Is it too difficult to achieve in vb.net?
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ofd1.InitialDirectory = "D:\Howard Stern\Video\HTVOD - 50 Cent & G-Unit - 2003 [WDM]"
ofd1.ShowDialog()
Dim filepath As String = ofd1.FileName
' MsgBox(filepath)
AxWindowsMediaPlayer1.URL = filepath
AxWindowsMediaPlayer1.Ctlcontrols.play()
' AxWindowsMediaPlayer1.Ctlcontrols.stop()
'getinfo()
Timer1.Enabled = True
End Sub
Function ConvertTime(ByVal TheTime As Integer)
' Converts Windows Media Player (AxWMP Component)
' Default Play Time in Milliseconds to either: (00:00) MM:SS (Minutes:Seconds)
' or HH:MM:SS (00:00:00) (Hours:Minutes:Seconds)
On Error Resume Next
Dim NewTime As String
Dim Sec As Single
Dim min As Single
Dim h As Single
Dim a As String = ""
If TheTime = 60 Then
ConvertTime = "1:00"
Exit Function
End If
If TheTime > 60 Then
Sec = TheTime
min = Sec / 60
min = Int(min)
Sec = Sec - min * 60
h = min / 60
h = Int(h)
min = min - h * 60
'If your current time in Seconds is less than 10 then designate a 0 prior to the single digit second - Prevents you from showing 0:1 as opposed to 0:01.
If Sec < 10 Then
a = "0"
End If
'edit this line to add Hours(HH:MM:SS) if you would like
ConvertTime = String.Format("{0}:{1}{2}", min, a, Sec)
End If
If TheTime < 60 Then
Sec = TheTime
min = Sec / 60
min = Int(min)
Sec = Sec - min * 60
h = min / 60
h = Int(h)
min = min - h * 60
If Sec < 10 Then
a = "0"
End If
ConvertTime = String.Format("{0}:{1}{2}", min, a, Sec)
End If
End Function
Sub getinfo()
lblTotalTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration)
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Get the duration of the avi file here while it is playing
lblTotalTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration)
lblCurrentTime.Text = ConvertTime(AxWindowsMediaPlayer1.Ctlcontrols.currentPosition)
AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
End Class

New Topic/Question
Reply
MultiQuote








|