网上搜了下,只找到了个PHP的类,只好照葫芦画瓢写了一个,目前只完成了读取的功能,由于本人水平有限,如有写得不妥的地方,还请各位能帮忙指出
类主文件:wmaExif.class.asp
测试程序:wma.asp
参考资料:
http://linle.ycool.com/post.1255557.html
http://www.itlearner.com/Article/2007/3944.shtml
类主文件:wmaExif.class.asp
- <%
- 'Author: dragonbbc
- 'Email: dragonbbc@163.com
- '参考文章:
- 'http://linle.ycool.com/post.1255557.html
- 'http://www.itlearner.com/Article/2007/3944.shtml
- '需指定的属性
- 'File
- '可用方法
- 'CheckSize 检查文件大小
- 'Parse 读取信息
- 'GetInfo(TagName)
- '常见TagName
- '标准Tag: Title, Artist, Copyright, Description
- '扩展Tag: WM/AlbumTitle, WM/EncodedBy, WM/Genre, WM/Lyrics, WM/Track, WM/Year, WM/URL, WM/UserWebURL, WMFSDKVersion, WM/TrackNumber
- Class wmaExif
- Public File '文件
- Private objStream
- Private headtag, bodytag, std_tag, ext_tag
- Private headsize,headext1,tagnum,headext2,headbuf,bodysize,bodybuf
- Private framebuf(),sectionbuf()
- Private items1, items2
- Private Sub Class_Initialize()
- headtag = "3026b2758e66cf11a6d900aa0062ce6c"
- bodytag = "3626b2758e66cf11a6d900aa0062ce6c"
- std_tag = "3326b2758e66cf11a6d900aa0062ce6c"
- ext_tag = "40a4d0d207e3d21197f000a0c95ea850"
- items1 = Array("Title", "Artist", "Copyright", "Description", "Reserved")
- 'items2 = Array("AlbumTitle", "EncodedBy", "Genre", "Lyrics", "Track", _
- ' "Year", "URL", "UserWebURL", "TrackNumber")
- End Sub
- Private Sub Class_Terminate
- on error resume next
- CloseStream
- End Sub
- 'GetInfo
- Public Function GetInfo(TagName)
- TagName = Replace(TagName, "/", "")
- If Eval("Not IsEmpty("&TagName&")") Then
- Execute("GetInfo = "&TagName)
- End If
- End Function
- 'CheckSize
- Public Function CheckSize()
- CheckSize = False
- CreateStream
- If ReadHeader = False Then Exit Function
- If ReadBody = False Then Exit Function
- If objStream.Size <> headsize + bodysize Then Exit Function
- CheckSize = True
- CloseStream
- End Function
- 'Parse
- Public Function Parse()
- CreateStream
- If ReadHeader = False Then Exit Function
- ReDim framebuf(tagnum)
- head_off = 1
- For j = 1 To tagnum
- frame_head = MidB(headbuf, head_off, 24)
- head_off = head_off + 24
- frametag = ReadHex(LeftB(frame_head, 16))
- framesize = ReadLong_UL(MidB(frame_head,17,4))
- 'framebuf(j) = MidB(headbuf,head_off-24,framesize)
- If frametag = std_tag Then
- Dim lenx(5)
- tmp_off = 0
- For i = 0 To 4
- lenx(i) = ReadShort_UL(MidB(headbuf, head_off+2*i, 2))
- tempstr = ReadString(MidB(headbuf, head_off+10+tmp_off, lenx(i)))
- tmp_off = tmp_off + lenx(i)
- Execute(items1(i)&" = tempstr")
- Next
- head_off = head_off + 10 + temp_off
- ElseIf frametag = ext_tag Then
- inum = ReadShort_UL(MidB(headbuf, head_off, 2))
- tmp_off = 2
- While k < inum And tmp_off+24 < framesize
- nlen = ReadShort_UL(MidB(headbuf, head_off+tmp_off, 2))
- nbuf = ReadString(MidB(headbuf, head_off+tmp_off+2, nlen))
- flag = ReadShort_UL(MidB(headbuf, head_off+tmp_off+2+nlen, 2))
- vlen = ReadShort_UL(MidB(headbuf, head_off+tmp_off+2+nlen+2, 2))
- vbuf = ReadString(MidB(headbuf, head_off+tmp_off+2+nlen+4, vlen))
- 'on error resume next
- Execute(Replace(nbuf,"/","")&" = vbuf")
- 'err.clear
- tmp_off = tmp_off + 6 + nlen + vlen
- k = k + 1
- Wend
- head_off = head_off + framesize-24
- Else
- head_off = head_off + framesize-24
- End If
- Next
- CloseStream
- End Function
- 'get the header
- Private Function ReadHeader()
- ReadHeader = False
- buf = objStream.Read(30)
- If ReadHex(LeftB(buf, 16)) <> headtag Then Exit Function
- headsize = ReadLong_UL(MidB(buf,17,4))
- headext1 = MidB(buf,21,4)
- tagnum = ReadLong_UL(MidB(buf,25,4))
- headext2 = MidB(buf,29,2)
- headbuf = objStream.Read(headsize-30)
- ReadHeader = True
- End Function
- 'get the body
- Private Function ReadBody()
- ReadBody = False
- buf = objStream.Read(24)
- If ReadHex(LeftB(buf, 16)) <> bodytag Then Exit Function
- bodysize = ReadLong_UL(MidB(buf,17,4))
- bodybuf = objStream.Read(bodysize-24)
- ReadBody = True
- End Function
- 'CreateStream
- Public Function CreateStream()
- on error resume next
- Set objStream = Server.CreateObject("ADODB.Stream")
- objStream.Type = 1
- objStream.Open
- Err.clear
- objStream.LoadFromFile File
- If err<>0 Then
- objStream.LoadFromFile server.mappath(File)
- End If
- Err.clear
- End Function
- 'CloseStream
- Public Function CloseStream()
- objStream.close
- Set objStream = nothing
- End Function
- 'Read String From Byte
- Private Function ReadString(binstr)
- If LenB(binstr) > 2 Then
- ReadString = LeftB(binstr, LenB(binstr)-2)
- Else
- ReadString = binstr
- End If
- End Function
- 'Read Hex From Byte
- Private Function ReadHex(binstr)
- ReadHex = ""
- on error resume next
- For i = 1 To LenB(binstr)
- ReadHex = ReadHex & Hex((AscB(MidB(binstr,i,1)) And &HF0)/16) & Hex(AscB(MidB(binstr,i,1)) And &H0F)
- Next
- ReadHex = LCase(ReadHex)
- End Function
- 'Read Unsigned Long(Little Endian) From Byte
- Private Function ReadLong_UL(binstr)
- ReadLong_UL = 0
- on error resume next
- ReadLong_UL = AscB(MidB(binstr,1,1)) + AscB(MidB(binstr,2,1))*256 + AscB(MidB(binstr,3,1))*65536 + AscB(MidB(binstr,4,1))*16777216
- End Function
- 'Read Unsigned Short(Little Endian) From Byte
- Private Function ReadShort_UL(binstr)
- ReadShort_UL = 0
- on error resume next
- ReadShort_UL = AscB(MidB(binstr,1,1)) + AscB(MidB(binstr,2,1))*256
- End Function
- End Class
- %>
- <!-- #include file="wmaExif.class.asp" -->
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>利用ASP获取WMA的TAG信息</title>
- </head>
- <body>
- <%
- dim info
- set info = New wmaExif
- set info.File=request("soundPath")
- If info.CheckSize = True Then
- info.Parse
- Response.write "歌名:"&info.GetInfo("Title")&"<br/>"
- Response.write "歌手:"&info.GetInfo("Artist")&"<br/>"
- Response.write "版权:"&info.GetInfo("CopyRight")&"<br/>"
- Response.write "注释:"&info.GetInfo("Description")&"<br/>"
- Response.write "专辑:"&info.GetInfo("WM/AlbumTitle")&"<br/>"
- Response.write "曲目:"&info.GetInfo("WM/TrackNumber")&"<br/>"
- Response.write "发行年份:"&info.GetInfo("WM/Year")&"<br/>"
- Response.write "类型:"&info.GetInfo("WM/Genre")&"<br/>"
- Else
- Response.Write "error"
- End If
- set info = Nothing
- %>
- </body>
- </html>
参考资料:
http://linle.ycool.com/post.1255557.html
http://www.itlearner.com/Article/2007/3944.shtml