Option Explicit Private boPause As Boolean '用于暂停/播放按钮的逻辑判断 Private Declare Function WritePrivateProfileString Lib "kernel32" _ Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) _ As Long '写ini文件的API函数声明 Private Sub file_exit_Click(Index As Integer) '菜单"退出"处理 Unload Form1 '终止,退出 End Sub Private Sub file_open_Click(Index As Integer) '功能:菜单"打开"处理 With OpenFileDlg '设置CommonDialog控件 .Flags = 0 '只允许打开单个文件 .MaxFileSize = 10000 '设置最大文件数 .Filter = "(*.mp3)|*.mp3" '只显示.mp3文件 .FileName = "" '设置初始文件路径名 .ShowOpen '显示对话框 End With If OpenFileDlg.FileName = "" Then 王亚彬个人资料 Exit Sub '若未选中文件则退出本过程陈乔恩男朋友 Else '若选中文件则设置提示文字并启动MCI设备 TitleWnd.Caption = "选中一个音乐文件[请点击播放按钮播放音乐]" 全程都在做的动漫 FileNameWnd.Caption = OpenFileDlg.FileName '显示音乐文件路径名 PlayMP3 MP3Player, OpenFileDlg.FileName '启动MCI设备播放音乐 MP3Player.Command = "stop" '通过stop、prev两命令使面板上的play按钮 MP3Player.Command = "prev" '有效等待用户通过鼠标单击方式发出播放命令 End If End Sub Private Sub Form_Load() '功能:载入面板初始设置 With Form1 '设置面板标题及边框样式 .Caption = "MP3播放实例[Written by Minipuss]" .BorderStyle = 1 End With With TitleWnd '设置提示窗口标题及前景(GREEN) .Caption = "目前无音乐文件被选中[请通过菜单进行选择]" .ForeColor = RGB(0, 255, 0) End With With FileNameWnd '设置路径名窗口标题及前景(GREEN) .Caption = "" .ForeColor = RGB(0, 255, 0) End With '调用写ini文件的函数在C:\windows\system.ini的[MCI]中添加 'mp3audio=mciqtz.drv使得系统MCI设备可MP3格式文件进行解码 '从而播放该格式音乐文件 WritePrivateProfileString "MCI", "mp3audio", "mciqtz.drv", "C:\windows\system.ini" boPause = False '初始化boPause=False End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) '功能:Aplication结束前善后处理 With MP3Player 'Aplication结束时停止播放音乐并关闭MCI设备 .Command = "stop" .Command = "close" End With End Sub 郁可唯个人资料Private Sub MP3Player_PauseClick(Cancel As Integer) '功能:暂停按钮点击事件处理 boPause = boPause Xor True 'boPause异或1 If boPause = True Then '第一次点击暂停按钮时暂停播放音乐 MP3Player.Command = "stop" Else '第二次点击暂停按钮时从中止处继续播放音乐 MP3Player.Command = "sound" End If End Sub Private Sub MP3Player_PlayClick(Cancel As Integer) '功能:播放按钮点击事件处理 MP3Player.Command = "sound" '点击播放按钮时从头播放音乐 End Sub Private Sub MP3Player_PlayCompleted(Errorcode As Long) '功能:音乐播放完毕事件处理 MP3Player.Command="prev" '音乐播放完毕后回到播放始点使播放按钮有效 End Sub Private Sub MP3Player_StopClick(Cancel As Integer) '功能:停止按钮点击事件处理 With MP3Player '停止播放音乐并回到播放始点使播放按钮有效 .Command = "stop" .Command = "prev" End With End Sub |
发布评论