Attribute VB_Name = "modMp3Info"
Private Type Info
    sTitle As String
    sArtist As String
    sAlbum As String
    sComment As String
    sYear As String
    sGenre As String
End Type

 Dim OldIndice As Long
 Public MP3Info As Info

Public Function GetMp3Info(sPassFilename As String) As Boolean
    
    Dim iFreefile As Integer
    Dim lFilePos As Long
    Dim sData As String * 128
    Dim sGenre() As String
    Dim NohayInfo As Boolean
    
    Const sGenreMatrix As String = "Blues|Classic Rock|Country|Dance|Disco|Funk|Grunge|" + _
    "Hip-Hop|Jazz|Metal|New Age|Oldies|Other|Pop|R&B|Rap|Reggae|Rock|Techno|" + _
    "Industrial|Alternative|Ska|Death Metal|Pranks|Soundtrack|Euro-Techno|" + _
    "Ambient|Trip Hop|Vocal|Jazz+Funk|Fusion|Trance|Classical|Instrumental|Acid|" + _
    "House|Game|Sound Clip|Gospel|Noise|Alt. Rock|Bass|Soul|Punk|Space|Meditative|" + _
    "Instrumental Pop|Instrumental Rock|Ethnic|Gothic|Darkwave|Techno-Industrial|Electronic|" + _
    "Pop-Folk|Eurodance|Dream|Southern Rock|Comedy|Cult|Gangsta Rap|Top 40|Christian Rap|" + _
    "Pop/Punk|Jungle|Native American|Cabaret|New Wave|Phychedelic|Rave|Showtunes|Trailer|" + _
    "Lo-Fi|Tribal|Acid Punk|Acid Jazz|Polka|Retro|Musical|Rock & Roll|Hard Rock|Folk|" + _
    "Folk/Rock|National Folk|Swing|Fast-Fusion|Bebob|Latin|Revival|Celtic|Blue Grass|" + _
    "Avantegarde|Gothic Rock|Progressive Rock|Psychedelic Rock|Symphonic Rock|Slow Rock|" + _
    "Big Band|Chorus|Easy Listening|Acoustic|Humour|Speech|Chanson|Opera|Chamber Music|" + _
    "Sonata|Symphony|Booty Bass|Primus|Porn Groove|Satire|Slow Jam|Club|Tango|Samba|Folklore|" + _
    "Ballad|power Ballad|Rhythmic Soul|Freestyle|Duet|Punk Rock|Drum Solo|A Capella|Euro-House|" + _
    "Dance Hall|Goa|Drum & Bass|Club-House|Hardcore|Terror|indie|Brit Pop|Negerpunk|Polsk Punk|" + _
    "Beat|Christian Gangsta Rap|Heavy Metal|Black Metal|Crossover|Comteporary Christian|" + _
    "Christian Rock|Merengue|Salsa|Trash Metal|Anime|JPop|Synth Pop"

    sGenre = Split(sGenreMatrix, "|")

    mvarFilename = sPassFilename

    


    If Not IsValidFile(sPassFilename) Then
      Form1.txtMp3Info.Visible = False
      GetMp3Info = False
      Exit Function
    End If
    
    GetMp3Info = True
    iFreefile = FreeFile
    lFilePos = FileLen(mvarFilename) - 127


    If lFilePos > 0 Then
    
        Open mvarFilename For Binary As #iFreefile
        Get #iFreefile, lFilePos, sData
        Close #iFreefile
    End If
    


    If Left(sData, 3) = "TAG" Then
        
        MP3Info.sTitle = Mid(sData, 4, 30)
        If MP3Info.sTitle <> Space(30) Then Form1.txtMp3Info.Text = "Titulo: " & (MP3Info.sTitle)
        MP3Info.sArtist = Mid(sData, 34, 30)
        If MP3Info.sArtist <> Space(30) Then Form1.txtMp3Info.Text = Form1.txtMp3Info.Text & vbCrLf & "Artista: " & (MP3Info.sArtist)
        MP3Info.sAlbum = Mid(sData, 64, 30)
        If MP3Info.sAlbum <> Space(30) Then Form1.txtMp3Info.Text = Form1.txtMp3Info.Text & vbCrLf & "Album: " & MP3Info.sAlbum
        MP3Info.sYear = Mid(sData, 94, 4)
        If MP3Info.sYear <> Space(4) Then Form1.txtMp3Info.Text = Form1.txtMp3Info.Text & vbCrLf & "Año: " & (MP3Info.sYear)
        MP3Info.sComment = Mid(sData, 98, 30)
        If MP3Info.sComment <> Space(30) Then Form1.txtMp3Info.Text = Form1.txtMp3Info.Text & vbCrLf & "Comentario: " & MP3Info.sComment
        Dim lGenre
        lGenre = Asc(Mid(sData, 128, 1))

        If lGenre <= UBound(sGenre) Then
            MP3Info.sGenre = sGenre(lGenre)
            If MP3Info.sGenre <> Space(128) Then Form1.txtMp3Info.Text = Form1.txtMp3Info.Text & vbCrLf & "Genero: " & MP3Info.sGenre & vbCrLf
        Else
            MP3Info.sGenre = ""
        End If
    Else
    NohayInfo = True
    End If

If NohayInfo = True Then
  Form1.txtMp3Info.Text = "No hay información"
End If

End Function

Private Function IsValidFile(ByVal sFilename) As Boolean
    Dim bOk As Boolean

    bOk = CBool(Dir(sFilename, vbHidden) <> "")
    
    Dim aExtensions, ext
    aExtensions = Array(".mp3", ".mp2", ".mp1")
    Dim bOkayExtension As Boolean
    bOkayExtension = False


    If bOk Then


        For Each ext In aExtensions


            If InStr(1, sFilename, ext, vbTextCompare) > 0 Then
                bOkayExtension = True
            End If
        Next
    End If
    
    IsValidFile = bOk And bOkayExtension
End Function

Public Function ShowMp3info(Modo As Integer, Optional X As Single, Optional Y As Single)

Dim Indice As Long
Dim Valido As Boolean
Dim DirecPathActual As String

On Error Resume Next

Form1.ListView1.ToolTipText = ""

If Modo = 1 Then GoTo NoNecesitaHitTest
If Form1.ListView1.HitTest(X, Y) Is Nothing Then
  Form1.txtMp3Info.Visible = False
  Exit Function
End If

Set Form1.ListView1.DropHighlight = Form1.ListView1.HitTest(X, Y)

GoTo NecesitaHitTest

NoNecesitaHitTest:

Set Form1.ListView1.DropHighlight = Form1.ListView1.ListItems.Item(Form1.ListView1.SelectedItem.Index)

NecesitaHitTest:

Indice = Form1.ListView1.DropHighlight.Index
Set Form1.ListView1.DropHighlight = Nothing

DoEvents

If OldIndice = Indice Then
  Exit Function
Else
  OldIndice = Indice
End If

DirecPathActual = MakeFullPath(Form1.ListView1, Indice)

If DirecPathActual = "" Then
  Form1.txtMp3Info.Visible = False
  Exit Function
End If

Form1.ListView1.ToolTipText = GetTypeName(DirecPathActual)
Valido = GetMp3Info(MakeFullPath(Form1.ListView1, Indice))

If Valido = True Then Form1.txtMp3Info.Visible = True

End Function
