利用VB制作MP3播放列表
發表于:2007-07-14來源:作者:點擊數:
標簽:
姜衛東、華云 RealPlayer是一款很好也是很常用的播放軟件,但它不直接支持MP3的連續播放。因此,我決定用 VB 編一個程序,它能搜索整個硬盤中的MP3文件,自動為RealPlayer制作播放列表。 界面設計 啟動VB,選擇“工程→引用”菜單,在彈出的對話框中選擇“Mi
姜衛東、華云
RealPlayer是一款很好也是很常用的播放軟件,但它不直接支持MP3的連續播放。因此,我決定用
VB編一個程序,它能搜索整個硬盤中的MP3文件,自動為RealPlayer制作播放列表。
界面設計
啟動VB,選擇“工程→引用”菜單,在彈出的對話框中選擇“Microsoft Scripting Runtime”?以便引用FileSystemObject,再選擇“工程→部件”,在彈出的對話框中選擇“Microsoft Common Dialog Control 6.0”和“Microsoft Rich Textbox Control 6.0”。
在窗體Form1上添加兩個命令按鈕Command1和Command2,它們的Caption屬性分別設置為“開始”和“保存”;一個列表框控件List1,用來顯示搜索到的MP3文件;一個組全框控件Combo1,將其List屬性設置為“C?\”、“D?\”、“E?\”、“F?\”、“G?\”、“H?\”等;再加入三個標簽控件:Label1、Label2和Label3,將RichTextBx1的名稱設置為“Text1”,Multiline屬性設置為True(運行結果如圖所示)。
源程序
接著輸入以下代碼:
Private Sub Command1_Click??
Dim fs As New FileSystemObject'建立FileSystemObject
Dim fd As Folder'定義Folder對象
Dim sfd As Folder
Set fd=fs.GetFolder?Combo1.Text?
Command1.Enabled=False
Screen.MousePointer=
vbHourglass
FindFile fd?″?.mp3″'Text1.Text
Command1.Enabled=True
Screen.MousePointer=vbDefault
End Sub
?。б韵逻^程實現查找指定分區下的所有MP3文件
Sub FindFile?fd As Folder?FileName As String?
Dim sfd As Folder?f As File
?。У谝徊糠郑翰檎以撐募A的所有文件
For Each f In fd.Files
Label2=f.Path
If UCase?f.Name?Like UCase?FileName?Then
List1.AddItem f.Path
label3=″共找到″&List1.ListCount&″首MP3文件″
End If
DoEvents
Next
?。У诙糠郑貉h查找所有子文件夾
For Each sfd In fd.SubFolders
FindFile sfd?FileName'循環查找
Next
End Sub
?。П4姘粹o的源代碼:
Private Sub Command2_Click??
CommonDialog1.Filter=″realplay播放列表文件??.ram?|?.ram″
CommonDialog1.ShowSave
For i=0 To List1.ListCount - 1
text1.Text=text1.Text&″file?///″&List1.List?i?&vbCrLf
Next
?。б韵麓a將文件名中的″\″替換為″/″
Dim intCount As Integer
Dim lngPos As Long
Dim intOptions As Integer
?。гO置初始信息
intCount=0
lngPos=0
With text1
Do
If text1.Find?″\″?lngPos??intOptions?=-1 Then'如果″\″沒找到
Exit Do
Else'如果文件名中有″\″,則換為″/″
lngPos=text1.SelStart+text1.SelLength
intCount=intCount+1'設置計數器
text1.SelText=″/″'替換
End If
Loop
End With
?。EXT1的內容保存為一個文件
Open CommonDialog1.FileName For Output As#1
Print#1?text1.Text
Close#1
Msgbox“文件”&CommonDialogl.FileName&“已成功保存”,vbMsgBoxSet-Foreground,“提示”
End Sub
以上程序在Windows 98SE,Windows Me VB6.0中文企業版中運行通過。
原文轉自:http://www.anti-gravitydesign.com