手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

读取MP3文件的ID3v1信息

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

52
53 "Tango", "Samba", "Folklore"}
54
55
56
57 Public Property MP3Tag() As String
58
59 Get
60
61 Return _MP3Tag
62
63 End Get
64
65 Set(ByVal value As String)
66
67 _MP3Tag = value.Trim
68
69 End Set
70
71 End Property
72
73
74
75 Public Property Title() As String
76
77 Get
78
79 Return _Title
80
81 End Get
82
83 Set(ByVal value As String)
84
85 _Title = value.Trim
86
87 End Set
88
89 End Property
90
91
92
93 Public Property Artist() As String
94
95 Get
96
97 Return _Artist
98
99 End Get
100
101 Set(ByVal value As String)
102
103 _Artist = value.Trim
104
105 End Set
106
107 End Property
108
109
110
111 Public Property Album() As String
112
113 Get
114
115 Return _Album
116
117 End Get
118
119 Set(ByVal value As String)
120
121 _Album = value.Trim
122
123 End Set
124
125 End Property
126
127
128
129 Public Property Comment() As String
130
131 Get
132
133 Return _Comment
134
135 End Get
136
137 Set(ByVal value As String)
138
139 _Comment = value.Trim
140
141 End Set
142
143 End Property
144
145
146
147 Public Property Genre() As String
148
149 Get
150
151 Return _Genre
152
153 End Get
154
155 Set(ByVal value As String)
156
157 _Genre = value.Trim
158
159 End Set
160
161 End Property
162
163
164
165 Public Property GenreID() As Byte
166
167 Get
168
169 Return _GenreID
170
171 End Get
172
173 Set(ByVal value As Byte)
174
175 _GenreID = value
176
177 End Set
178
179 End Property
180
181
182
183 Public Property Year() As String
184
185 Get
186
187 Return _Year
188
189 End Get
190
191 Set(ByVal value As String)
192
193 _Year = value.Trim
194
195 End Set
196
197 End Property
198
199 End Class
200
201
202
203 上面的类只包含了mp3歌曲信息对应的数据结构,我们还要为它添加具体读取mp3文件信息的过程:
204
205
206
207 Public Function GetMp3FileInfo(ByVal fname As String) As Boolean
208
209
210
211 'Open the filestream
212
213 Dim msfile As FileStream
214
215 Try
216
217 msfile = New FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
218
219 If Not (msfile.CanRead) Then
220
221 Throw New IO.IOException("无法读取文件:" fname)
222
223 End If
224
225 Catch Ex As Exception
226
227 Throw New IO.IOException("读取文件发生错误!" Ex.Message)
228
229 End Try
230
231
232
233 Dim ID3(TAGLEN - 1) As Byte
234
235 Dim BinReader As BinaryReader
236
237 Dim StrInfo As String
238
239
240
241 '使用BinaryReader来读取信息
242
243 BinReader = New BinaryReader(msfile)
244
245
246
247 msfile.Position = 0
248
249 msfile.Seek(-TAGLEN, SeekOrigin.End)
250
251
252
253 StrInfo = CBytesToString(BinReader.ReadBytes(3))
254
255
256
257 '判断标签头是否为 TAG
258
259 If StrInfo.ToUpper = "TAG" Then
260
261
262
263 '读取标题信息
264
265 StrInfo = CBytesToString(BinReader.ReadBytes(30)).Replace(Chr(0), "")
266
267 _Title = StrInfo
268
269
270
271 '读取艺术家信息
272
273 StrInfo = CBytesToString(BinReader.ReadBytes(30)).Replace(Chr(0), "")
274
275 _Artist = StrInfo
276
277
278
279 '读取专辑信息
280
281 StrInfo = CBytesToString(BinReader.ReadBytes(30)).Replace(Chr(0), "")
282
283 _Album = StrInfo
284
285
286
287 '读取出版年度信息
288
289 StrInfo = CBytesToString(BinReader.ReadBytes(4)).Replace(Chr(0), "")
290
291 _Year = StrInfo
292
293
294
295 '读取备注信息
296
297 StrInfo = CBytesToString(BinReader.ReadBytes(30)).Replace(Chr(0), "")
298
299 _Comment = StrInfo

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!