⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playmp3.frm

📁 功能描述]VB 5.0下开发的MP3播放器
💻 FRM
📖 第 1 页 / 共 3 页
字号:
      Left            =   6150
      ToolTipText     =   "更换界面"
      Top             =   975
      Width           =   825
   End
   Begin VB.Image Image1 
      Height          =   315
      Index           =   12
      Left            =   7110
      ToolTipText     =   "最小化"
      Top             =   60
      Width           =   300
   End
   Begin VB.Line Line2 
      Visible         =   0   'False
      X1              =   48
      X2              =   68
      Y1              =   42
      Y2              =   42
   End
End
Attribute VB_Name = "PlayMp3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim bLineShowFlag As Boolean    '按钮是否按下
Dim cFileName() As String   '文件名数组
Dim nCount As Integer   '当前播放的文件数
Dim bOpenFlag As Boolean    '文件打开标志,
Dim bPlayFlag As Boolean  '文件是否正在播放标志
Dim bSkipFlag As Integer    '文件跳过标志
Dim bRepeatFlag As Integer, nRepeatTime As Integer  '循环标志,两次快进或后退的间隔秒数
Dim nFrameCount As Single   '总桢数
Dim bVolumeFlag As Integer  '声道标志
Dim nLeftVolume As Integer '左声道音量
Dim nRightVolume As Integer '右声道音量
Dim bVolumeValueFlag As Boolean '取音量标志
Dim DrawStart As Boolean, bDrawLineFlag As Boolean  '开始拖动标志,画线标志
Dim nX As Integer, nY As Integer    '旧的坐标
Dim nPicCount As Integer, bOnTopFlag As Boolean    '界面序号,总在最前标志

Private Sub Form_Load()
    If App.PrevInstance = True Then
        End
    End If
        Randomize   '产生0-4之间的随机数
        nPicCount = Int((4 - 0 + 1) * Rnd + 0)
        Pic_Set nPicCount   '设置界面
        Mp3Play.Authorize "LightBringer", "1441658209"  'MP3控件注册
        Mp3Play.SetErrorMode 1  '允许MP3控件的错误提示
        ReDim cFileName(1) As String   '重新定义文件名数组
End Sub


Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
   nX = x   '记录旧的鼠标坐标
   nY = y
   DrawStart = True '可以开始拖动
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim TempPoint As POINTAPI, TempRect As RECT
    
    Line_Move 0, False  '隐藏所有按钮
    Select Case bVolumeFlag '显示当前声道状态
        Case 0
            Label1.Caption = "立体声"
        Case -1
            Label1.Caption = "左声道"
        Case 1
            Label1.Caption = "右声道"
    End Select
    
    If DrawStart Then   '可以拖动
        With TempPoint
            .x = x
            .y = y
            ClientToScreen Me.hwnd, TempPoint   '把当前的鼠标坐标转换为屏幕坐标
            TempRect.Left = .x - nX '左顶点=当前坐标-上次鼠标的坐标
            TempRect.Top = .y - nY
            TempRect.Right = .x + (Me.Width / 15 - nX)  '右下脚坐标=当前坐标+(表单宽度或高度/15-上次鼠标的坐标)VB中的控件的宽度和高度/15之后才为实际像素值
            TempRect.Button = .y + (Me.Height / 15 - nY)
        End With
        If bDrawLineFlag = True Then    '如果已经画虚线框
            DrawFocusRect GetDC(0), PicRect '把虚线框抹掉
        End If
        DrawFocusRect GetDC(0), TempRect    '画虚线框
        bDrawLineFlag = True    '虚线框已经画完
        PicRect.Left = TempPoint.x - nX '保存本次坐标,做抹除虚线框用
        PicRect.Top = TempPoint.y - nY
        PicRect.Right = TempPoint.x + (Me.Width / 15 - nX)
        PicRect.Button = TempPoint.y + (Me.Height / 15 - nY)
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    DrawStart = False   '不可以拖动
    If bDrawLineFlag = True Then    '如果已经画虚线框
        DrawFocusRect GetDC(0), PicRect '把虚线框抹掉
        Me.Move PicRect.Left * 15, PicRect.Top * 15 '把表单移至当前位置
    End If
    bDrawLineFlag = False   '虚线框已经抹除,可以重新画
End Sub

Private Sub Image1_Click(Index As Integer)
    Dim nValue As Integer   '控件的返回值
    
    Line_Click True '允许按钮显示
    bLineShowFlag = True    '按钮显示按下状态1/5秒
    Timer1.Interval = 200
    On Error GoTo error_handle
    Select Case Index
        Case 0  '关闭
            If bPlayFlag = True Then '有文件打开
                    bOpenFlag = False   '打开文件标志为假
                    bPlayFlag = False   '播放文件标志为假
                    bSkipFlag = 100 '重新打开
                    Mp3Play.Close   '关闭文件
                    Line5.X2 = Line5.X1
                    ErrorLabel.Caption = "MP3 播放器 V2.0     赵洪涛编于2000年7月"
            End If
        
        Case 1  '暂停
            
            If bPlayFlag = True Then    '有文件打开
                bPlayFlag = False   '播放文件标志为假
                Mp3Play.Pause   '暂停
            End If
                    
        Case 2  '播放   '已经选中文件 AND 已经打开 AND 未播放
            Dim nValues As Integer
            
            If nCount > 0 And bOpenFlag = True And bPlayFlag = False Then
                ErrorLabel.Caption = "正在播放第" & nCount & "个文件 : " & _
                    Right(cFileName(nCount), Len(cFileName(nCount)) - _
                    Len(cFileName(0)) - 1)
                nValues = Int(Mp3Play.TotalTime / 1000)
                Label5.Caption = "文件长度:" & Int(nValues / 60) & "分" & nValues Mod 60 & "秒"
                Label5.Caption = Label5.Caption & " 帧数:" & Mp3Play.FrameCount & " 采样:"
                Label5.Caption = Label5.Caption & Int(Mp3Play.BitRate / 1000) & "K"
                Label5.Caption = Label5.Caption & " 音频:" & Int(Mp3Play.SampleFrequency / 1000) & "K"
                Mp3Play.Play    '开始播放
                bPlayFlag = True    '播放文件标志为真
            End If
            
        Case 3  '后退
            If bPlayFlag = True And nRepeatTime >= 20 Then
                If nFrameCount - 800 >= 1 Then  '未退到文件头
                    nRepeatTime = 0
                    Mp3Play.Seek nFrameCount - 800  '后退800桢
                End If
            End If
        Case 4  '快进
            If bPlayFlag = True And nRepeatTime >= 20 Then
                If nFrameCount + 800 <= Mp3Play.FrameCount Then '未到文件尾
                    nRepeatTime = 0
                    Mp3Play.Seek nFrameCount + 800
                End If
            End If

        
        Case 5  '上一个文件
            If UBound(cFileName) > 1 And bPlayFlag = True Then   '选中了多个文件 AND 正在播放
                
                bSkipFlag = -1  '播放上一个文件
                
                If nCount > 1 Then  '当前文件数不是第一个
                    nCount = nCount - 1 '设定当前文件数
                Else
                    If bRepeatFlag = 1 Then '整体循环
                        nCount = UBound(cFileName)  '当前文件是第一个则跳到最后一个
                    End If
                End If
                
                If bOpenFlag = True Then    '已有文件打开
                    Mp3Play.Close   '把打开的文件关闭
                End If
            End If
        
        Case 6
            If UBound(cFileName) > 1 And bPlayFlag = True Then    '选中了多个文件 AND 正在播放
                
                bSkipFlag = 1    '播放下一个文件
                
                If nCount < UBound(cFileName) Then  '当前文件数不是最后一个
                    nCount = nCount + 1 '设定当前文件数
                Else
                    If bRepeatFlag = 1 Then '整体循环
                        nCount = 1  '当前文件是最后一个则跳到第一个
                    End If
                End If
                
                If bOpenFlag = True Then    '已有文件打开
                    Mp3Play.Close   '把打开的文件关闭
                    bOpenFlag = False
                End If
            End If
        
        Case 7  '退出
            End
        
        Case 8  '循环单首
            If bRepeatFlag = -1 Then    '取消循环
                bRepeatFlag = 0
                Image4(0).Visible = True    '显示不循环图标
                Image4(1).Visible = False
                Image4(2).Visible = False
            Else    '设置循环标志
                bRepeatFlag = -1
                Image4(0).Visible = False
                Image4(1).Visible = True    '显示循环图标
                Image4(2).Visible = False
            End If
        
        Case 9  '循环所有
            If bRepeatFlag = 1 Then '取消循环
                bRepeatFlag = 0
                Image4(0).Visible = True    '显示不循环图标
                Image4(1).Visible = False
                Image4(2).Visible = False
            Else    '设置循环标志
                bRepeatFlag = 1
                Image4(0).Visible = False
                Image4(1).Visible = False
                Image4(2).Visible = True     '显示循环图标
            End If

        Case 10 '选取文件
            bSkipFlag = -100 '什么都不做
            If bOpenFlag = True Then
                Mp3Play.Close
            End If
            
            Label5.Caption = ""
            Label5.Left = Picture1.Width * 15
            Get_FileName    '获取文件
        Case 11
            frmAbout.Show vbModal
            
        Case 12 '最小化
            Me.WindowState = 1
        
        Case 13 '减小音量
            If bOpenFlag = True Then
                Select Case bVolumeFlag
                    Case 0  '当前为立体声
                        If nLeftVolume - 4 > 0 Then '左声道音量>0
                            nLeftVolume = nLeftVolume - 4   '左声道-4
                        Else
                            nLeftVolume = 0
                        End If
                        
                        If nRightVolume - 4 > 0 Then    '右声道音量>0
                            nRightVolume = nRightVolume - 4 '右声道-4
                        Else
                            nRightVolume = 0
                        End If
                        
                        Mp3Play.SetVolumeP nLeftVolume, nRightVolume    '设置音量
                        
                    Case -1 '当前为左声道
                        If nLeftVolume - 4 > 0 Then
                            nLeftVolume = nLeftVolume - 4   '左声道-4
                        Else
                            nLeftVolume = 0
                        End If
                                                
                        Mp3Play.SetVolumeP nLeftVolume, 0    '设置音量
                        
                    Case 1   '当前为右声道
                        If nRightVolume - 4 > 0 Then
                            nRightVolume = nRightVolume - 4 '右声道-4
                        Else
                            nRightVolume = 0
                        End If
                        
                        Mp3Play.SetVolumeP 0, nRightVolume    '设置音量
                End Select
            End If
        Case 14 '增加音量
            If bOpenFlag = True Then
                Select Case bVolumeFlag
                    Case 0
                        If nLeftVolume + 4 < 100 Then
                            nLeftVolume = nLeftVolume + 4   '左声道+4
                        Else
                            nLeftVolume = 100
                        End If
                        
                        If nRightVolume + 4 < 100 Then
                            nRightVolume = nRightVolume + 4 '右声道+4
                        Else
                            nRightVolume = 100
                        End If
                        
                        Mp3Play.SetVolumeP nLeftVolume, nRightVolume    '设置音量
                        
                    Case -1
                        If nLeftVolume + 4 < 100 Then
                            nLeftVolume = nLeftVolume + 4   '左声道+4
                        Else
                            nLeftVolume = 100
                        End If
                                                
                        Mp3Play.SetVolumeP nLeftVolume, 0    '设置音量
                    Case 1
                        If nRightVolume + 4 < 100 Then
                            nRightVolume = nRightVolume + 4 '右声道+4
                        Else
                            nRightVolume = 100
                        End If
                        
                        Mp3Play.SetVolumeP 0, nRightVolume    '设置音量
                End Select
            End If
            
        Case 15 '更换界面
            If nPicCount = 4 Then
                nPicCount = 0
            Else
                nPicCount = nPicCount + 1
            End If
            
            Pic_Set nPicCount   '更换界面
    End Select
    
    Exit Sub
    
error_handle:
            ErrorLabel.Caption = Error
            Resume Next
End Sub

Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    Line_Move Index, True   '显示按钮
    Label1.Caption = Image1(Index).ToolTipText  '显示注释
End Sub

Sub Line_Move(Index As Integer, bShowFlag As Boolean)

    If bShowFlag = True Then    '允许按钮显示
        Line1.X1 = Image1(Index).Left
        Line1.X2 = Image1(Index).Left + Image1(Index).Width
        Line2.X1 = Image1(Index).Left
        Line2.X2 = Image1(Index).Left + Image1(Index).Width
        Line3.X1 = Image1(Index).Left
        Line3.X2 = Image1(Index).Left
        Line4.X1 = Image1(Index).Left + Image1(Index).Width
        Line4.X2 = Image1(Index).Left + Image1(Index).Width
        
        Line1.Y1 = Image1(Index).Top
        Line1.Y2 = Image1(Index).Top
        Line2.Y1 = Image1(Index).Top + Image1(Index).Height
        Line2.Y2 = Image1(Index).Top + Image1(Index).Height
        Line3.Y1 = Image1(Index).Top
        Line3.Y2 = Image1(Index).Top + Image1(Index).Height
        Line4.Y1 = Image1(Index).Top
        Line4.Y2 = Image1(Index).Top + Image1(Index).Height
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -