The ASF is fully named advanced system format, which is a kind of media format that MS vigorously packed and has been widely supported. Its most important branch is the WMV for audio and the WMV of video, of course, asf itself. Download the following address to the ASF format document: http://www.microsoft.com/windows/WindowsMedia/Format/ASFSPEC.ASPX
The ASF format consists of a different function ASF object. Each object has a Guid to identify, you only need to identify the object, you can find the information you want to use by the object format. Media information content in the ASF head object ASF_Header_Object, the head of the subject and contains several sub-objects, which the media information about the objects it three: ASF_Codec_List_Object, ASF_Content_Description_Object, ASF_Extended_Content_Description_Object, this article is to read and write for these three objects .
'Several music information object ASF format Private Const ASF_Header_Object = "{75B22630-668E-11CF-A6D9-00AA0062CE6C}" Private Const ASF_Codec_List_Object = "{86D15240-311D-11D0-A3A4-00A0C90348F6}" Private Const ASF_Content_Description_Object = "{75B22633-668E-11CF-A6D9-00AA0062CE6C}" Private Const ASF_Extended_Content_Description_Object = "{D2D0A440-E307-11D2-97F0-00A0C95EA850}" 'GUID Object ID Private Type GUID dwData1 As Long wData2 As Integer wData3 As Integer abData4 (7) As ByteEnd type 'genre, my own definition, not standard yo Private Enum MediaType mciMIDI = 1 mciMP3 = 2 mciASF = 4 mciVIDEO = 8 mciWAVE = 16End Enum' load music information structure Private type MusicInfo FileName As String MusicType As MediaType Title As String Artist As String Album As String Year As String Lyrics As String Writer As String Composer As String Bits As String Sample As String Length As LongEnd Type'ASF object identification structure Private Type ObjHeader ID As GUID Size (1) As LongEnd Type'ASF File head object structure Private type asfheader headerinfo as objh eader NumOfHeader As Long Reserved1 As Byte Reserved2 As ByteEnd Type'ASF description structure Private Type ContentDescription TitleLength As Integer AuthorLength As Integer CopyrightLength As Integer DescriptionLength As Integer RatingLength As IntegerEnd Type'ASF tag structure described Private Type DescriptorValue Type As Integer Length As IntegerEnd TypePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long) Private Declare Function StringFromCLSID Lib "ole32" (pclsid As GUID, lpsz As Long) As Long
Private function Guidtostr (ID AS GUID) AS STRING DIM S AS STRING, I as Long, J AS Long S = Space (38) J = StringFromClsid (ID, I) IF J = 0 Then CopyMemory Byval Strptr (s), byval i , 76 guidtostr = s end ifend function
Private Function GetASFInfo (udtInfo As MusicInfo) As Boolean Dim asfh As ASFHeader, bo As ObjHeader, TmpInfo As MusicInfo Dim fd As ContentDescription, dv As DescriptorValue, gd As GUID Dim a () As String, b () As Byte, Pos As Long , Freeno As INTEGER, EFL AS INTEGER DIM S AS STRING, I As Long, K AS INTEGER, L As String, VL AS String ON Error Goto Fail Freeno = FreeFile Pos = 1 Open Udtinfo.fileName For binary as #freeno tmpinfo = udtinfo with tmpinfo get #freeno, POS, Asfh s = guidtostr (asfh.headerinfo.id) IF s <> asf_header_object the Goto Fail POS = POS LEN (ASFH) for l = 1 to as ASFH. Numofheader get #freeno, POS, BO S = guidtostr (bo 2) select case s case asf_codec_list_object get #freeno, GD Get #Freeno,, i for j = 1 to i get #freeno, DV Redim B (DV.LENGTH * 2 - 1) Get #freeno,, B Get #freeno, EFL Redim B (EFL * 2 - 1) Get #Freeno, B En = B En = TRIM $ (Replace $ (EN , vbnullchar, ""), if IF INSTR (1, En, ")> 0 THEN A = Split (en,", ") IF INSTR (1, A (0)," Kbps ", vbtextcompare"> 0 dam .ss = val (a (0)) & "kbps"
END IF IF INSTR (1, A (1), "KHz", vbtextcompare> 0 Then .sample = VAL (A (1)) & "kHz" end if end if elseif dv.type = 1 Then 'here can take To video format information, because there is no purpose, there is no written .MusicType = .MusicType or mcivideo endiff get #freeno, EFL Redim B (EFL - 1) Get #Freeno, B Next Case asf_content_description_object get #freeno, FD Redim B (fd.titlelength - 1) Get #freeno,, B En = B En = TRIM $ (Replace $ (En, VBnullchar, "))) .title = EN Redim B (fd.authorlength - 1) Get #Freeno, B En = B En = TRIM $ (Replace $ (En, Vbnullchar, ")) . At .year <1900 or val val (.year)> 2100 Then Redim B (fd.copyrightlength - 1) get #freeno,, b en = b En = TRIM $ (Replace $ (en, vbnullchar , "")) A = split (en, ") for i = 0 to ubound (a) IF val (a (i))> 0 Then .year =
VAL (A (i)) exit for end ixt supported_content_description_object get #freeno, K for j = 1 to k Get #Freeno, EFL Redim B (EFL - 1) Get #Freeno,, B En = B En = LCase $ (Replace $ (En, Vbnullchar, ")))) Get #Freeno, DV SELECT CASE DV.TYPE CASE 0, 1 Redim B (DV.LENGTH - 1) Get #freeno, B VL = B VL = TRIM $ (Replace $ (VL, VBNULLCHAR, ")) Select Case En Case" Title ".title = VL Case "Author" if .artist = "" "" WM / albumartist ".Artist = VL case" wm / write ".writer = VL case" wm / composer ".Composer = VL case" WM / Albumtitle ".Album = VL case" WM / Lyrics "
.Lyrics = replace $ (VL, "", "") Case "WM / OriginalReleaseYear" if .year = "" "WM / YEAR". Year = VAL (VL) End Select Case 2, 3 redim b (3) get #freeno,, b case 4 redim b (7) get #freeno, B Case 5 redim b (1) get #freeno,, B end Select Next End SELECT POS = POS BO .Size (0) Next end with udtinfo = tmpinfo getasfinfo = truefail: Close #freenoend function
Private Sub Command1_Click () DIM I as Long, INF ASMICINFO, S AS STRING INF.FileName = Text1.Text If getMusicInfo (INF) THEN S = "file:" & Inf.FileName & Vbcrlf S = S & "Song Name: "& Inf.Title & VBCRLF S = S &" Record: "& Inf.Album & Vbcrf S = S &" Singer: "& Inf.Artist & Vbcrlf S = S &" Law: "& Inf.writer & Vbrlf = S & "Composes:" & Inf.composer & Vbcrf S = S & "Age:" & Inf.Year & Vbcrf S = S & "Sampling:" & Inf.bits & VBCRLF S = S & "Bits:" & inf.sample & vbcrlf s = s & "lyrics:" & inf.LYRICS ELSE S = "Unable to take music information" end if msgbox send Sub This is a code associated with the upper part, for some unfinished functions, You can find http://blog.9cbs.net/homezj/archive/2005/04/15/349005.aspx