Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am creating a Audio Player Application using DirectX SDK and VB .NET, i want to show the user Duration and Time elapsed of the Audio File, how can i achieve this?
P.S I'm Using VS 2010 Ultimate, Windows 7 Ultimate 64 bit...
Posted

Easiest way is to use the WindowsApiCodePack, which will let you just ask windows for the duration - there is a description of how to do exactly that here: How to get the length (duration) of a media File in C# on Windows 7[^]
 
Share this answer
 
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim CurrentPosition As Double
        If IsVideo Then
            CurrentPosition = VideoFile.CurrentPosition
        Else
            CurrentPosition = AudioFile.CurrentPosition
        End If
        'HScrollBar1.Value = Convert.ToInt32(CurrentPosition)
        'TrackOffset.Value = Convert.ToInt32(CurrentPosition)
        ColorSlider1.Maximum = AudioFile.Duration
        ColorSlider1.Value = AudioFile.CurrentPosition
        Dim ElapsedTime As TimeSpan = New TimeSpan(0, 0, CurrentPosition)
        ToolStripLabel5.Text = Int((ColorSlider1.Value / ColorSlider1.Maximum) * 100).ToString() & "%"
        ToolStripLabel1.Text = Format(Int((AudioFile.CurrentPosition) / 3600), "00") & ":" & _
                               Format(Int((AudioFile.CurrentPosition) / 60) Mod 60, "00") & ":" & _
                               Format(Int((AudioFile.CurrentPosition) Mod 60), "00").ToString & " / " & _
                               Format(Int(AudioFile.Duration / 3600), "00") & ":" & _
                               Format(Int((AudioFile.Duration - Int(AudioFile.Duration / 3600) * 3600) / 60), "00") & ":" & _
                             Format(Int(AudioFile.Duration - Int(AudioFile.Duration / 60) * 60), "00")
        If ColorSlider1.Value Then
            ToolStripLabel3.Text = "Position: " & Int(AudioFile.CurrentPosition)
            If IsVideo Then
                If CurrentPosition = VideoFile.Duration Then Button8.PerformClick() : CheckRepeat()
            Else
                If CurrentPosition = AudioFile.Duration Then Button8.PerformClick() : CheckRepeat()
               
            End If
        End If



    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900