Results 1 to 6 of 6

Thread: [2005] Get the time attribute of an MP3 file

  1. #1

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    [2005] Get the time attribute of an MP3 file

    Is there anyway to get the length of an MP3 or WMA file without opening the file. Windows explorer shows that information, so I would assume that is available though .NET.

    Nothing in FileInfo or Attributes had what I was looking for.

    Any ideas?
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  2. #2
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: [2005] Get the time attribute of an MP3 file

    When you say length, do you mean the time required ?

  3. #3

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: [2005] Get the time attribute of an MP3 file

    Sorry, let me specify. I mean total length or total time of the song.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  4. #4
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Get the time attribute of an MP3 file

    Use MCIsendStrings

    VB Code:
    1. Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" ( _
    2.   ByVal lpstrCommand As String, _
    3.   ByVal lpstrReturnString As String, _
    4.   ByVal uReturnLength As Int32, _
    5.   ByVal hwndCallback As Int32) As Int32
    6.  
    7.  
    8.     Private Sub OpenMedia(ByVal fname As String) As String      'loads the file
    9.         _FileName = fname
    10.  
    11.         _alias = System.Guid.NewGuid.ToString.Replace("-"c, "")
    12.         Dim cmd As String = "open " & _FileName & " alias " & _alias
    13.  
    14.        mciSendString(cmd, retVal, retLength, 0)
    15.     End Function
    16.  
    17.     Private Sub GetLength()           'gets the length of the loaded file
    18.         Dim retVal As New String("X"c, 128)
    19.         Dim cmd As String = "status " & _alias & " length"
    20.         mciSendString(cmd, retVal, 128, 0)
    21.         If Double.TryParse(l, _Length) = False Then
    22.             _Length = -1
    23.         End If
    24.     End Sub

    I didn't test this. I took it from a media player that was geared for video I was writing, so there may be some errors. But that and this, should get you through it I would think.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  5. #5

    Thread Starter
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: [2005] Get the time attribute of an MP3 file

    There has to be a better way than that? Doesn't that just get the file length, not the time (in minutes and seconds) of the song?

    Does anyone know of an easier way to get the time of an MP3? If not, I think I might just use the built-in method in .NET to get the total size of the file and just estimate the length of the file since I don't need the exact amount.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  6. #6
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: [2005] Get the time attribute of an MP3 file

    That does get the time ( I think in nano seconds), but I may just be thinking of the project I'm working on right now that uses DirectShow Editing. Another way you could do it is us a mediaplayer component. But that's just adding overhead since WMP is based off of SendStrings
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (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