得到MP3中隱藏的信息
發(fā)表時(shí)間:2024-02-18 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]為了保護(hù)音樂者的版權(quán),在MP3文件中有一段特意存儲(chǔ)版權(quán)說明的信息,眾多的MP3播放器軟件都提供了修改和讀取MP3文件中隱藏信息的功能,那么這些信息到底存儲(chǔ)在哪里呢?如何得到這些信息呢?本文將為大家提供得到MP3信息的模塊。 首先,定義一個(gè)公共類型Mp3tag如下: Public Typ...
為了保護(hù)音樂者的版權(quán),在MP3文件中有一段特意存儲(chǔ)版權(quán)說明的信息,眾多的MP3播放器軟件都提供了修改和讀取MP3文件中隱藏信息的功能,那么這些信息到底存儲(chǔ)在哪里呢?如何得到這些信息呢?本文將為大家提供得到MP3信息的模塊。
首先,定義一個(gè)公共類型Mp3tag如下:
Public Type Mp3tag
Artist As String ’Artist 存儲(chǔ)歌手信息
Album As String ’Album 存儲(chǔ)唱片專輯信息
Title As String ’Title 存儲(chǔ)標(biāo)題信息
Year As String ’Year 存儲(chǔ)年代信息
Comments As String ’Comments 存儲(chǔ)備注信息
Genre As Integer ’Genre 存儲(chǔ)音樂風(fēng)格序列
End Type
然后,定義一個(gè)獲取MP3信息的函數(shù),它將返回這些信息,代碼如下:
Public Function GetMp3Tag(FName As String) As Mp3tag
Dim Artist As String
Dim Album As String
Dim Title As String
Dim Year As String
Dim Comments As String
Dim Genre As Integer
If FName = "" Then Exit Function
If Dir(FName) = "" Then Exit Function
Dim FileNum As Integer
FileNum = FreeFile ’得到一個(gè)自由的文件號
Dim strInput As String
Open FName For Binary Access Read As FileNum ’以二進(jìn)制形式打開文件
If LOF(FileNum) < 128 Then
Close FileNum
Exit Function
End If
Seek FileNum, LOF(FileNum) - 127 ’把文件指針移動(dòng)到MP3信息處
strInput = Space(3)
Get FileNum, , strInput
If strInput <> "TAG" Then ’如果沒有發(fā)現(xiàn)信息標(biāo)識(shí),就關(guān)閉文件
Close FileNum
GoTo Done:
End If
strInput = Space(30)
Get FileNum, , strInput
Title = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Artist = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Album = Trim(strInput)
strInput = Space(4)
Get FileNum, , strInput
Year = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Comments = Trim(strInput)
strInput = Space(1)
Get FileNum, , strInput
Genre = Asc(strInput)
Done:
GetMp3Tag.Title = Title
GetMp3Tag.Artist = Artist
GetMp3Tag.Album = Album
GetMp3Tag.Year = Year
GetMp3Tag.Year = Comments
If Genre < 0 Or Genre > 254 Then Genre = 12
GetMp3Tag.Genre = CInt(Genre)
Close FileNum
End Function
注意:MP3文件對音樂的風(fēng)格進(jìn)行了限制,共254種。Genre返回的只是MP3風(fēng)格的序列號,具體還需要定位,在這里我把所有類型以常數(shù)形式列出,每個(gè)類型之間用" "號隔開。
Private 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"
把以上代碼寫到一個(gè)模塊中(.Bas),然后在窗體上加入5個(gè)TextBox和1個(gè)ComboBox控件,其中5個(gè)TextBox控件分別用來顯示一首Mp3文件的以下信息:歌手、年代、唱片、評論、標(biāo)題,ComboBox控件用來顯示歌曲的風(fēng)格。再放一個(gè)Command控件,其標(biāo)題為“顯示信息”,在它的Click事件中加入以下代碼:
Private sub Command1_click()
Dim mp3Tag as Mp3tag
mp3tag = GetMp3Tag ("c:\Song.mp3")
Text1.Text = mp3tag.Artist
Text2.Text = mp3tag.Album
Text3.Text = mp3tag.Title
Text4.Text = mp3tag.Year
Text5.Text = mp3tag.Comments
Combo1.ListIndex = mp3tag.Genre
End Sub
在窗體的加載過程中加入如下代碼:
Private Sub Form_Load()
Dim i As Integer,GenreArray() As String
GenreArray = Split(sGenreMatrix, " ")
For i = LBound(GenreArray) To UBound(GenreArray)
Combo1.AddItem GenreArray(i)
Next i
End Sub
以上代碼在VB6 \Win2000中測試通過。