|
-
Oct 9th, 2006, 03:31 PM
#1
Thread Starter
No place like 127.0.0.1
[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?
-
Oct 9th, 2006, 03:59 PM
#2
Banned
Re: [2005] Get the time attribute of an MP3 file
When you say length, do you mean the time required ?
-
Oct 9th, 2006, 04:08 PM
#3
Thread Starter
No place like 127.0.0.1
Re: [2005] Get the time attribute of an MP3 file
Sorry, let me specify. I mean total length or total time of the song.
-
Oct 9th, 2006, 05:07 PM
#4
Frenzied Member
Re: [2005] Get the time attribute of an MP3 file
Use MCIsendStrings
VB Code:
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" ( _
ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Int32, _
ByVal hwndCallback As Int32) As Int32
Private Sub OpenMedia(ByVal fname As String) As String 'loads the file
_FileName = fname
_alias = System.Guid.NewGuid.ToString.Replace("-"c, "")
Dim cmd As String = "open " & _FileName & " alias " & _alias
mciSendString(cmd, retVal, retLength, 0)
End Function
Private Sub GetLength() 'gets the length of the loaded file
Dim retVal As New String("X"c, 128)
Dim cmd As String = "status " & _alias & " length"
mciSendString(cmd, retVal, 128, 0)
If Double.TryParse(l, _Length) = False Then
_Length = -1
End If
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.
-
Oct 10th, 2006, 01:18 PM
#5
Thread Starter
No place like 127.0.0.1
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.
-
Oct 10th, 2006, 01:24 PM
#6
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|