Results 1 to 6 of 6

Thread: [RESOLVED] Audio Duration

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Resolved [RESOLVED] Audio Duration

    Importing an audio file and playing by pressing a button with this:

    Code:
    My.Computer.Audio.Play(TextBox1.Text)
    Can anyone advise on how I can display the duration of the audio in Label 1?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Audio Duration

    You're not able to do anything else, other than determine how/when the audio should stop using My.Computer.Audio.Play. The other method I know of is to use the active x windows media player and use the .CurrentMedia.DurationString to get the length of the current audio being played:
    Code:
    Label1.Text = AxWindowsMediaPlayer1.currentMedia.durationString
    Last edited by dday9; Apr 30th, 2013 at 09:29 AM. Reason: Corrected the method name, still can't find documentation on it though.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Audio Duration

    Thanks dday! i was concerned that using windows media player stuff might prove to be tricky/annoying. actually, having played with it after your recommendation, it seems fairly flexible.

    thanks

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Audio Duration

    Hi...

    Using the following code to display in my label (lblPlayer1Duration) how long of the current audio is left.

    At the moment, it's displaying in seconds. eg if something is 3minutes and 10seconds long, it displays as 190. How can I format the label so it is

    0:03:10

    and counts down from there?

    Code:
        Private Sub timerPlayerOneRemaining_Tick(sender As System.Object, e As System.EventArgs) Handles timerPlayerOneRemaining.Tick
            Dim t As Double = Math.Floor(wmpPlayer1.currentMedia.duration - wmpPlayer1.Ctlcontrols.currentPosition)
    
            ' Display the time remaining in the current media.
            lblPlayer1Duration.Text = t.ToString()
    
        End Sub

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Audio Duration

    lblPlayer1Duration.Text = TimeSpan.FromSeconds(t).ToString.Substring(0, 8)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    198

    Re: Audio Duration

    Perfect! Thank you so much for your help!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width