首页 | 社区 | 博客 | 招聘 | 文章 | 新闻 | 下载 | 读书 | 代码
亲,您未登录哦! 登录 | 注册

利用VB制作MP3播放列表

打印文章

分享到:
姜卫东、华云

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

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )

编程爱好者论坛

本栏最新文章