如何取得 MP3 音樂檔的中的歌名、演唱者..等相關資訊 ( ID3 )
如何讀取 MP3 音樂檔的中的歌名、演唱者..等相關資訊 ( ID3 )
VB.Net 寫法 :
' 放表單裡 (Form)
Private Sub cmdGetID3_Click(ByVal Sender As System.Object, ByVal e As System.EventArgs) _
Handles cmdGetID3.Click
With Get_MP3_ID3("D:\MP3\50 Cent - Candy Shop.mp3")
MsgBox(.SongTitle, 64, "Song Title")
MsgBox(.Album, 64, "Album")
MsgBox(.Artist, 64, "Artist")
MsgBox(.Year_Renamed, 64, "Year")
MsgBox(.Comment, 64, "Comment")
MsgBox(.Genre, 64, "Genre")
End With
End Sub
' 放模組裡 (Module)
Public Structure MP3ID3
<VBFixedString(3)> Public Tag As String
<VBFixedString(30)> Public SongTitle As String
<VBFixedString(30)> Public Artist As String
<VBFixedString(30)> Public Album As String
<VBFixedString(4)> Public Year_Renamed As String
<VBFixedString(30)> Public Comment As String
Dim Genre As Byte
End Structure
Public Function Get_MP3_ID3(ByVal strFileName As String) As MP3ID3
Dim mp3file As MP3ID3
Dim intFileNo As Short
intFileNo = FreeFile
FileOpen(intFileNo, strFileName, OpenMode.Binary)
Seek(intFileNo, FileLen(strFileName) - 127)
FileGet(intFileNo, mp3file)
FileClose(intFileNo)
Get_MP3_ID3 = mp3file
End Function
================================================================
VB6 寫法 :
' 放表單裡 (Form)
Private Sub cmdGetID3_Click()
With Get_MP3_ID3("D:\MP3\50 Cent - Candy Shop.mp3")
MsgBox .SongTitle, 64, "Song Title"
MsgBox .Album, 64, "Album"
MsgBox .Artist, 64, "Artist"
MsgBox .Year, 64, "Year"
MsgBox .Comment, 64, "Comment"
MsgBox .Genre, 64, "Genre"
End With
End Sub
' 放模組裡 (Module)
Public Type MP3ID3
Tag As String * 3
SongTitle As String * 30
Artist As String * 30
Album As String * 30
Year As String * 4
Comment As String * 30
Genre As Byte
End Type
Public Function Get_MP3_ID3(strFileName As String) As MP3ID3
Dim mp3file As MP3ID3
Dim intFileNo As Integer
intFileNo = FreeFile
Open strFileName For Binary As intFileNo
Seek #intFileNo, FileLen(strFileName) - 127
Get #intFileNo, , mp3file
Close #intFileNo
Get_MP3_ID3 = mp3file
End Function