trrunde Skrevet 2. mars 2008 Del Skrevet 2. mars 2008 Ønsker lage et program som leser id3 tags, noen som har forslag til hvordan jeg kan få det til? Har ikke brukt vb siden vb6 :s men nå har jeg vs 2008 Lenke til kommentar https://www.diskusjon.no/topic/919479-lese-id3-tags/
Cerwell Skrevet 2. mars 2008 Del Skrevet 2. mars 2008 Her er en modul jeg har brukt med hell i VB6. Vet ikke hvem forfatteren er, men gi beskjed om noen kjenner den igjen, så krediterer jeg den. Attribute VB_Name = "Id3Module" Public Type Id3 'This type is standard for Title As String * 30 ' Id3 Tags Artist As String * 30 ' Although later versions Album As String * 30 ' use comments for 28 bytes sYear As String * 4 ' and they use the 2 remaining bytes for "TrackNumber"! Comments As String * 30 Genre As Byte End Type Public id3Info As Id3 ' Declare a variable as the id3 type Public GenreArray() As String ' we use this array to fill all the Genre's ( look in form load) Public Const sGenreMatrix = "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" ' Thank you Leigh Bowers ' We can use the split function to fill this into an array Public Function GetId3(Filename As String) Dim TaG As String * 3 ' We use this variable to make sure the file has an ID3TAG On Error GoTo lErr Open Filename For Binary As #1 ' we open the file as binary for total control (we need it for the Genre part) Get #1, FileLen(Filename) - 127, TaG ' Id3 tags are at the end of the mp3 file(and as the type shows it is 128 bytes) If TaG = "TAG" Then ' "TAG" is put at position filesize-127 to show that this file indeed contains an Id3 Get #1, FileLen(Filename) - 124, id3Info ' if the file has a tag, we put it into our earlier declared variable id3info Else Dim intPos As Integer intPos = InStrRev(Filename, "\") id3Info.Artist = Mid(Filename, intPos + 1, Len(Filename)) ' if the "TAG" wasnt at position filesize-127 If id3Info.Artist = "" Then id3Info.Artist = "Error Getting ID3" End If Close #1 Filename = "" ' close the file Exit Function lErr: Select Case Err.Number Case 75 id3Info.Artist = Filename id3Info.Title = "" Case Else 'MsgBox "Id3info error: " & Err.Description & " " & Err.Number End Select ' Now about the Genre ' It works like this, it contains a code in numbers ranging form 1 to 147 ' each of these numbers represents a certain Genre like "HipHop" = 7 etc etc. ' the guy who maid the Id3 Tags made a list for the codes and there were originally 80 of them ' then the dudes at winamp extended this so today there are about 150 ' this is a pain in the ass to figure out, still there are some info about this on the www. ' Now, a very cool person by the name of Leigh Bowers, has done this. you can search for the code ' on planet source, "MP3Snatch v2.0", but that code has a couple of flaws in the genre part as it uses ' a string*21 instead of a Byte, and on that code you cant write the tag, only read it. ' so i have included Leighs code wich has 147 of the Genre's, very cool. ' if you want the Genre directly, try filling a combobox with the GenreArray and then use combo1.listindex to match the Genre(code) (number) End Function Public Function SaveId3(Filename As String, Mp3Info As Id3) Dim TaG As String * 3 ' We use this variable to make sure the file has an ID3TAG Open Filename For Binary As #1 ' we open the file as binary for total control (we need it for the Genre part) Get #1, FileLen(Filename) - 127, TaG ' Id3 tags are at the end of the mp3 file(and as the type shows it is 128 bytes) If TaG = "TAG" Then ' "TAG" is put at position filesize-127 to show that this file indeed contains an Id3 Put #1, FileLen(Filename) - 124, Mp3Info ' if the file has a tag, we put our new information in the file Else Put #1, FileLen(Filename) - 127, "TAG" ' else we put the "TAG" there first, Close #1 Call SaveId3(Filename, Mp3Info) ' then we call this function again so we fill the info this time End If Close #1 ' close the file ' Remember when filling the Mp3info variable ' set the genre part to the number corresponding to the Genre ' it will save it as 1 byte End Function Lenke til kommentar https://www.diskusjon.no/topic/919479-lese-id3-tags/#findComment-10685220
trrunde Skrevet 2. mars 2008 Forfatter Del Skrevet 2. mars 2008 (endret) takker for svar, har visual studio 2008 så er ikke alt som er like kompatibelt med vb6 kode, men jeg får gjøre mitt beste på å få den til Okey, første problem: på den public function getID3 får jeg en error som sier statement not valid in namespace, når jeg søker på hjelp kommer det opp at jeg må denne må være i en class, module o.l Men denne er jo allerede i en module :s Noen smarte vb folk som vet hva jeg må gjøre? Endret 2. mars 2008 av trrunde Lenke til kommentar https://www.diskusjon.no/topic/919479-lese-id3-tags/#findComment-10685572
GeirGrusom Skrevet 2. mars 2008 Del Skrevet 2. mars 2008 Det der er også bare for ID3 v1.1 Track nummer er forøvrig det siste bytet i comments (som egentlig skal være 31 bytes langt hvis jeg ikke husker feil) Grunnen til at dette ikke fungerer hos deg, er fordi dette er skrevet for VB6 Public Structure Id3 <MarshalAs(UnmanagedType.LPStr, SizeConst=30)> Public Title As String <MarshalAs(UnmanagedType.LPStr, SizeConst=30)> Public Artist As String <MarshalAs(UnmanagedType.LPStr, SizeConst=30)> Public Album As String <MarshalAs(UnmanagedType.LPStr, SizeConst=4)> Public Year As String <MarshalAs(UnmanagedType.LPStr, SizeConst=29)> Public Comments As String Public Track As Byte Public Genre As Byte End Structure Jeg har ikke peiling på hvordan man leser ID3 v2, fordi det rett og slett ikke er beskrevet hvor i filen dette ligger i dokumentasjonen... :S Lenke til kommentar https://www.diskusjon.no/topic/919479-lese-id3-tags/#findComment-10686617
Cerwell Skrevet 3. mars 2008 Del Skrevet 3. mars 2008 Saks fra http://www.id3.org/id3v2.4.0-frames Here are the algorithms to be used in the calculation. The known data must be the offset of the start of the indexed data (S), the offset of the end of the indexed data (E), the number of index points (N), the offset at index i (Oi). We calculate the fraction at index i (Fi). Oi is the offset of the frame whose start is soonest after the point for which the time offset is (i/N * duration). The frame data should be calculated as follows: Fi = Oi/L * 2^b (rounded down to the nearest integer) Offset calculation should be calculated as follows from data in the frame: Oi = (Fi/2^b)*L (rounded up to the nearest integer) Lenke til kommentar https://www.diskusjon.no/topic/919479-lese-id3-tags/#findComment-10694388
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå