The list of music files is also a problem that cannot be ignored. It is certainly possible, but it is not complicated in the M3U format that everyone is familiar with. MediaPlayer or WinAmp supports it. It is very versatile, so it is much easier than WPL. Let me introduce the production and reading and writing of the M3U format file.
M3U is a text file, starting with # extM3u, each music stripe for 1-2 lines, when there is extended information, the first line adopts #extinf: start, the second line is the file name; when there is no extended information, it is just simple One line is the file name; the file name can contain the path or not, the music file should be in the same directory with the M3U file when not included.
The entire format is as simple, the following is a read function, and returned when reading a M3U, and each collection item is a string of music information. To get the specific content of this string, available GetM3UInfo functions Returns the MusicInfo structure.
The saving function is not perfect, you need to pass a M3U collection, because the M3U string information is transmitted, each entry can only be deleted, and cannot be modified directly. If you are interested, you can take a class package Musicinfo structure and provide modification.
Private Function LoadM3UFile (strFileName As String) As Collection Dim a () As String, s1 As String, s As String, i As Long, FileLine () As String Dim blnAddOK As Boolean, strFilePath As String, colTemp As Collection, LineNum As Long On Error GoTo fail Set colTemp = New Collection If Dir (strFileName) = vbNullString Then GoTo fail strFilePath = Left $ (strFileName, InStrRev (strFileName, "/")) Open strFileName For Binary As # 1 s = Input (LOF (1) , 1) Close if s = vbnullstring the Goto Fail I = INSTR (1, S, "# Extm3u", vbtextcompare) if i = 0 THEN GOTO FAIL I> 1 THEN S = MID $ (S, I) S = Trim $ (Replace $ (S, VBCRLF & VBCRLF, VBCRLF)) Fileline = Split (S, VBCRLF) Do while linenum <= ubound (fileline) s = trim $ (fileline (linenum)) IF S <> vbnullstring the blnaddok = false IF ucase $ (Left $ (s, 8)) <> "#extinf:" Then IF INSTR (1, S, ": /") = 0 THEN S = Strfilep ath & s If Dir (s, vbNormal Or vbHidden Or vbReadOnly Or vbSystem Or vbArchive) <> vbNullString Then blnAddOK = True Else If Dir (s, vbNormal Or vbHidden Or vbReadOnly Or vbSystem Or vbArchive) <> vbNullString Then blnAddOK = True Else s = STRFILEPATH & MID $ (S, INSTRREV (S, "/") 1) IF DIR (S, VBNORMAL or VBHIDDEN or VBREADONLY or VBSYSTEM or VBARCHIVE) <> vbnullstring the blnaddok =
True end if end50p. (s)> 0 THEN COLTEMP.ADD S, S END IF END IF ELSE S = MID $ (S, 9) LINENUM = LINENUM 1 S1 = TRIM $ (FileLine (LINENUM) ) If s1 <> vbNullString Then If InStr (1, s1, ": /") = 0 Then s1 = strFilePath & s1 If Dir (s1, vbNormal Or vbHidden Or vbReadOnly Or vbSystem Or vbArchive) <> vbNullString Then blnAddOK = True Else If Dir (S1, VBNORMAL or VBHIDDEN or VBREADONLY or VBSYSTEM or VBARCHIVE) <> vbnullstring the blnaddok = true else s1 = strfilepath & mid $ (S1, INSTRREV (S1, "/") 1) If Dir (s1, vbNormal Or vbHidden Or vbReadOnly Or vbSystem Or vbArchive) <> vbNullString Then blnAddOK = True End If End If If blnAddOK Then If GetMCIType (s1)> 0 Then colTemp.Add s & vbCrLf & s1, s1 End If End If end if end if end if linenum = linenum 1 loopfail: set loadingm3ufile =
colTempEnd FunctionPrivate Function SaveM3U (strFileName As String, colM3UList As Collection) As Boolean Dim FreeNo As Long, i As Long, a () As String On Error GoTo fail If colM3UListe.Count> 0 Then FreeNo = FreeFile Open strFileName For Output As #FreeNo Print #freeno, "# Extm3u" for i = 1 to colm3uliste.count a = split (colm3uliste (i), vbcrlf) if Ubound (a)> 0 Then Print #Freeno, "#extinf:" & colm3uliste (i) else Print #FreeNo, colM3UListe (i) End If Next Close #FreeNo SaveM3U = True End Iffail: End FunctionPrivate Function GetM3UInfo (M3UItem As String) As MusicInfo Dim a () As String, b () As String, tmpinfo As MusicInfo Dim i As Long, J AS String if Trim (m3uitem) = vbnullstring the exit function a = split (m3uitem, vbcrlf) if Ubound (a)> 0 THEN J = INSTR (1, A (0), ",") K = INSTR (1, A (0), "-") IF j> 0 and k> 0 THEN B = Split (a (0), ",") IF VAL (b (0))> 0 THENTMPINFO.LENGTH = VAL (b (0)) B = Split (TRIM $ (1)), "- ") IF b (0) <> vbnullstring the tmpinfo.artist = trim $ (b (0))) IF b (1) <> vbnullstring the tmpinfo.title = trim $ (b (1)) Else S = TRIM $ ( A (1)) i = INSTRREV (S, "/") IF i> 0 Tmpinfo.title = MID $ (S, i 1) Else Tmpinfo.title = s end if end if end if tmpinfo.filename =
a (1) Else tmpinfo.FileName = a (0) End If GetM3UInfo = tmpinfoEnd FunctionPrivate Sub Command1_Click () Dim tmp As Collection, tmpinfo As MusicInfo, s As String Set tmp = LoadM3UFile (Text1.Text) If tmp.Count> 0 THENTMPINFO = GETM3UINFO (TMP (Tmp.count)) s = "file:" & tmpinfo.filename s = S & VBCRLF & "Song Name:" & Tmpinfo.title S = S & VBCRLF & "Singer:" & Tmpinfo. Artist S = S & VBCRLF & "Song length:" & tmpinfo.length & "second" msgbox s end ifend subgabox s
This is a code associated with the upper part. For some unfained functions, you can find http://blog.9cbs.net/Homezj/archive/2005/04/15/349005.aspx in the previous article