Hot to get (mp3) file value/rating

Thony

New member
Joined
May 18, 2011
Messages
3
Location
Heerenveen, Netherlands, Netherlands
Programming Experience
10+
Hi,

I'm trying to get the rating value of a mp3 file. I was expecting this to be a default option of mp3tag components, but i haven't found one that could show the value.

Does anyone know how to get this value ?
 
This information can be retrieved from the Windows Shell. Add reference to the Shell library (COM tab), it's called "Microsoft Shell Controls And Automation". In code open a Folder using Namespace function, it will let you get FolderItem objects and use GetDetailsOf function to get the details. Using GetDetailsOf with the folder.Items collection will get you the available column headers which are index based, and GetDetailsOf with a FolderItem where you specify the column index for which to get a possible value. "Rating" is here a column (which could be at index 20) and for example "Unrated" or "3 Stars" could be the column value. Here's a code sample that specifically targets the Rating column and get the value for all items in a folder:
Dim shell As New Shell32.Shell
Dim folder = shell.NameSpace("D:\Media")

Dim columns As New Dictionary(Of String, Integer)
For i As Integer = 0 To Short.MaxValue
    Dim header = folder.GetDetailsOf(folder.Items, i)
    If String.IsNullOrEmpty(header) Then
        Exit For 'no more columns
    Else
        columns(header) = i
    End If
Next

If columns.ContainsKey("Rating") Then
    For Each item As Shell32.FolderItem In folder.Items
        Dim rating = folder.GetDetailsOf(item, columns("Rating"))
        Debug.WriteLine("{0} : {1}", rating, item.Name)
    Next
End If
 
This information can be retrieved from the Windows Shell. Add reference to the Shell library (COM tab), it's called "Microsoft Shell Controls And Automation". In code open a Folder using Namespace function, it will let you get FolderItem objects and use GetDetailsOf function to get the details. Using GetDetailsOf with the folder.Items collection will get you the available column headers which are index based, and GetDetailsOf with a FolderItem where you specify the column index for which to get a possible value. "Rating" is here a column (which could be at index 20) and for example "Unrated" or "3 Stars" could be the column value. Here's a code sample that specifically targets the Rating column and get the value for all items in a folder:

sir, i have looking for something similar to get image size and yes your code also work with images. But how can i directly access or get a single file without goes though all files in a folder?

any help would be highly appreciated :)

thanks in advance...

best regards
 
how can i directly access or get a single file without goes though all files in a folder?
You can get a FolderItem directly with folder.ParseName(filename).
 
You can get a FolderItem directly with folder.ParseName(filename).

thanks a lot for your fast reply sir.

i am not clear? would you please give me a simple code just to get exact information.

because i think i still need to first follow this code get the indexes:
VB.NET:
Dim columns As New Dictionary(Of String, Integer)
For i As Integer = 0 To Short.MaxValue
    Dim header = folder.GetDetailsOf(folder.Items, i)
    If String.IsNullOrEmpty(header) Then
        Exit For 'no more columns
    Else
        columns(header) = i
    End If
Next

above code right?

thanks again for your reply though :)

best regards
 
That code is to get the column header strings and their indexes. You need that index later when calling GetDetailsOf. This code gets details of one item:
Dim rating = folder.GetDetailsOf(item, columns("Rating"))
I told you how to get one item with folder.ParseName.
 
Back
Top