| Option Explicit Dim MaxVal As Long '进度条Max值变量 Dim MyInd As Integer '播讲的文件索引变量 Dim sF As String '要播放的M3U文件 Private Sub cmdNext_Click() '“下一首”按钮代码 PlayNext List1.SetFocus '让按钮好看点,下同 End Sub Private Sub cmdPause_Click() '“暂停”按钮代码 MMControl1.Command = "Pause" List1.SetFocus End Sub Private Sub cmdPlay_Click() '“播放”按钮代码 List1.SetFocus If MMControl1.Command = "Stop" Or MMControl1.Command = "Pause" Then MMControl1.Command = "Play" Else Call PlayMe '交给PlayMe处理 End If End Sub Private Sub cmdExit_Click() '“退出”按钮代码 MMControl1.Command = "close" '关闭以释放资源 End End Sub Private Sub cmdPre_Click() '“前一首”按钮代码 Timer1.Enabled = False List1.SetFocus If MyInd = 0 Then '当前是第一首则播放最后一首 List1.ListIndex = List1.ListCount - 1 Else '否则播放前一首 List1.ListIndex = MyInd - 1 End If MyInd = List1.ListIndex '这个变量要记得改哟 Call PlayMe End Sub Private Sub Form_Load() '程序加载 Timer1.Enabled = False Timer1.Interval = 1000 List1.BackColor = vbBlack List1.ForeColor = vbYellow MMControl1.Visible = False MyInd = 0 cmdOpen.Value = True '“打开”按钮被按下 'OpenM3u '打开M3U文件 'PlayMe '播放 End Sub Private Sub cmdOpen_Click() '“打开”按钮代码 On Error GoTo openerr: List1.Clear CommonDialog1.Filter = "(*.m3u)|*.m3u" '这个不用说了吧 CommonDialog1.ShowOpen sF = CommonDialog1.FileName OpenM3u '打开M3U文件 Exit Sub openerr: Timer1.Enabled = False '出错则不能让计时器工作 '出错信息自己写吧 End Sub '当点击右上角的“×”按钮时 Private Sub Form_Unload(Cancel As Integer) MMControl1.Command = "Close" '关闭设备以释放资源 End Sub Private Sub List1_dblClick() '双击列表框事件 MyInd = List1.ListIndex cmdPlay.Value = True End Sub '判断是否要播放下一首 Private Sub MMControl1_StatusUpdate() If MMControl1.Position = MMControl1.Length Then PlayNext End If End Sub Private Sub PlayMe() '播放媒体文件 With MMControl1 '以下语句是不是有点罗嗦? .FileName = List1.List(MyInd) .Command = "stop" .Command = "close" .Command = "Open" .Command = "play" End With MaxVal = MMControl1.Length Timer1.Enabled = True Me.Caption = List1.List(MyInd) '显示正在播放的文件名称 ProgressBar1.ToolTipText = "播放总数:" & List1.ListCount & "首" ''显示播放文件总数 End Sub Private Sub Timer1_Timer() '进度条的Max和Value值 ProgressBar1.Max = MaxVal ProgressBar1.Value = MMControl1.Position End Sub Private Sub PlayNext() '播放下一首 Timer1.Enabled = False ProgressBar1.Value = 0 MyInd = MyInd + 1 '当然加1了 If MyInd >= List1.ListCount Then MyInd = 0 Call PlayMe '呵呵,偷懒一下吧 List1.ListIndex = MyInd End Sub Private Sub OpenM3u() '打开M3U文件并存入内存 On Error GoTo M3uErr Dim AllLines As New Collection '内存中集全 Dim CurrentLine As Long '当前行集合索引 Dim nextLine As String '从文件中读出的每一行 Dim InFile As Integer '文件的描述符 InFile = FreeFile Open sF For Input As InFile '打开文件 While Not EOF(InFile) Line Input #InFile, nextLine AllLines.Add nextLine Wend Close InFile Dim i As Integer '以下为提取各行 For i = 0 To AllLines.Count - 1 CurrentLine = CurrentLine + 1 If AllLines.Count < CurrentLine Then CurrentLine = 1 End If If AllLines.Count > 0 Then '当然要加入列表框啦 List1.AddItem AllLines.Item(CurrentLine) End If Next i MMControl1.FileName = List1.List(0) '老M终于有文件要处理了 List1.ListIndex = 0 ' 列表框第一项高亮——老M就是靠它来判断下一首是什么 Exit Sub M3uErr: '......我累了 End Sub |
关注此文的读者还看过: