如何用vb提取音乐文件专辑封面
发布网友
发布时间:2022-04-22 21:29
我来回答
共1个回答
热心网友
时间:2022-05-03 01:17
所谓“专辑封面”,其实就是AlbumArt,ID3V2中称APIC。
不出意外的话,可以读文件ID3V2,下面的代码实现了。不过假定文件必须有专辑图,也就是APIC。窗体上放Command1,文件路径根据实际修改。
Private Sub Command1_Click()
Dim DAT() As Byte
Dim sDAT() As Byte
Dim FileSize As Long '文件长度
Dim btnACPI As Long
Dim btnStart As Long
Dim btnExit As Long
btnACPI = 0: btnStart = 0: btnExit = 0
FileSize = FileLen("E:\360data\重要数据\桌面\怒放的生命.mp3") '获取文件长度
ReDim DAT(FileSize - 1) As Byte
Open "E:\360data\重要数据\桌面\怒放的生命.mp3" For Binary As #1
Get #1, , DAT
Close
For i = 0 To UBound(DAT)
If i + 3 <= UBound(DAT) Then
If Hex(DAT(i)) & Hex(DAT(i + 1)) & Hex(DAT(i + 2)) & Hex(DAT(i + 3)) = "41504943" And btnACPI = 0 Then
btnACPI = i + 3
btnExit = DAT(btnACPI + 1) * (16777216#)
btnExit = btnExit + DAT(btnACPI + 2) * (65536#) '计算帧大小
btnExit = btnExit + DAT(btnACPI + 3) * (256#)
btnExit = btnExit + DAT(btnACPI + 4) + 61440
End If
End If
If btnACPI <> 0 Then
If i + 3 <= UBound(DAT) Then
If Hex(DAT(i)) & Hex(DAT(i + 1)) = "FFD8" And btnStart = 0 Then
btnStart = i
Exit For
End If
End If
End If
Next i
ReDim sDAT(btnExit - btnStart) As Byte
For i = 0 To UBound(sDAT)
sDAT(i) = DAT(i + btnStart)
Next i
Open "E:\360data\重要数据\桌面\专辑封面.jpg" For Binary As #1
Put #1, , sDAT
Close
End Sub