1:播放指定文件夹内的所有歌曲
2:顺序播放,就是自动下一首。
‘添加windowsmediaplayer控件 一个timer控件即可使用
Option Explicit
Dim list2() As String, B可播放文件数As Integer '可以播放的文件
Dim list() As String '存放所有的文件名
Dim total As Long'文件总个数
Dim now As Long'用来记录当前读取的文件的排序
Private Sub Form_Load()
Timer1.Interval = 200
now = 1
total = 0
getAll "C:\WINDOWS\Media"'指定音乐文件夹
'输出文件的个数
Call F存入可播放文件名
If B可播放文件数>0 Then
Me.WindowsMediaPlayer1.URL = list2(now)
Else
MsgBox "没有音乐文件"
End If
End Sub
'遍历指定目录下的文件 并将所有的文件名放入数组list
Function getAll(rootF)
Dim fso As Object, folder As Object, subfolder As Object, file As Object
Set fso = CreateObject("scripting.filesystemobject")'创建FSO对象
Set folder = fso.getfolder(rootF)'得到文件夹对象
For Each subfolder In folder.subfolders '遍历子文件夹
Call getAll(subfolder) '递归,查找该文件夹的子文件夹
Next
For Each file In folder.Files '遍历根文件夹下的文件
Debug.Print folder
Debug.Print file '输出文件名
total = total + 1
ReDim Preserve list(total) As String
list(total) = file
Next
Set fso = Nothing
Set folder = Nothing
Set fso = Nothing
End Function
Function F存入可播放文件名()
Dim i As Integer
B可播放文件数= 0
For i = 1 To total
If Right(list(i), 3) = "mp3" Or Right(list(i), 3) = "wav" Then
B可播放文件数= B可播放文件数+ 1
ReDim Preserve list2(B可播放文件数)
list2(B可播放文件数) = list(i)
End If
Next
End Function
Private Sub Timer1_Timer()
If Me.WindowsMediaPlayer1.playState = wmppsStopped Then
now = now + 1
If now >B可播放文件数Then now = 1
Me.WindowsMediaPlayer1.URL = list2(now)
Me.WindowsMediaPlayer1.Controls.play
End If
End Sub
在我博客中有几篇相关代码,你进去看吧:
http://hi.baidu.com/zgmg/blog/item/d2715cf4551bbad5f3d38535.html
SHIP'S NAME: MV.LONG TIANOWNERS: ADANI SHIPPING(CHINA) CO.,LTD
是“大连阿达尼船务有限公司”的船。(网站http://vip.sol.com.cn/dasco/index.asp http://www.dasco.com.cn)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)