利用VB制作MP3播放列表

王朝厨房·作者佚名  2007-01-04
宽屏版  字体: |||超大  

姜卫东、华云

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

'第一部分:查找该文件夹的所有文件

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

'第二部分:循环查找所有子文件夹

For Each sfd In fd.SubFolders

FindFile sfdFileName'循环查找

Next

End Sub

'保存按钮的源代码:

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

'以下代码将文件名中的″\″替换为″/″

Dim intCount As Integer

Dim lngPos As Long

Dim intOptions As Integer

'设置初始信息

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

'将TEXT1的内容保存为一个文件

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中文企业版中运行通过。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有