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

📄 mmusic.cls

📁 自己做的俄罗斯方块游戏,vb开发
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Mmusic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'msi音乐处理类模块
'部分函数参照api手册改写
'mciSendString也请参考api手册
'
'
Option Explicit
Private salias As String          '副名
Private sFilename As String       '文件名(作为音乐播放的标识)
Private nLength As Single         '音乐长度
Private nPosition As Single       '播放的位置
Private sStatus As String         '现状态
Private bWait As Boolean          '是否等待某触发
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Sub mmOpen(ByVal sTheFile As String)
    Dim nReturn As Long
    Dim sType As String
    sFilename = sTheFile
    If salias <> "" Then
        mmClose
    End If
    Select Case UCase$(Right$(sTheFile, 3))          '判断为哪种类型音乐
       Case "WAV"
          sType = "Waveaudio"
       Case "AVI"
          sType = "AviVideo"
       Case "MID"
          sType = "Sequencer"
       Case Else
          Exit Sub
    End Select
    salias = Right$(sTheFile, 3) & Minute(Now)
    'salias = sTheFile
    If InStr(sTheFile, " ") Then sTheFile = Chr(34) & sTheFile & Chr(34)
    '发送信息到mci,这里是open音乐文件
    nReturn = mciSendString("Open " & sTheFile & " ALIAS " & salias & " TYPE " & sType & " wait", "", 0, 0)
End Sub

Public Sub mmClose()         '释放先open的资源
    Dim nReturn As Long
    If salias = "" Then Exit Sub   '副名为空则退出mmclose方法,下面语句执行速度比较慢
    nReturn = mciSendString("Close " & salias, "", 0, 0)
    salias = ""
    'sFilename = ""
End Sub

Public Sub mmPause()         '暂停播放
    Dim nReturn As Long
    If salias = "" Then Exit Sub  '同上
    
    nReturn = mciSendString("Pause " & salias, "", 0, 0)

End Sub
Public Sub mmResume()        '恢复播放
    Dim nReturn As Long
    If salias = "" Then Exit Sub
    nReturn = mciSendString("Resume " & salias, "", 0, 0)

End Sub

Public Sub mmPlay()          '播放
    Dim nReturn As Long
    If salias = "" Then Exit Sub
    If bWait Then                             'wait有值则等待响应再播放(响应键要定义)
        nReturn = mciSendString("Play " & salias & " wait", "", 0, 0)
    Else
        nReturn = mciSendString("Play " & salias, "", 0, 0)
    End If
End Sub

Public Sub mmStop()                          '停止播放
    Dim nReturn As Long
    If salias = "" Then Exit Sub
    nReturn = mciSendString("Stop " & salias, "", 0, 0)
End Sub

Public Sub mmSeek(ByVal nPosition As Single)

'End Sub
    Dim nReturn As Long
    
    nReturn = mciSendString("Seek " & salias & " to " & nPosition, "", 0, 0)

End Sub
Property Get filename() As String   '得到播放音乐的标识
    filename = sFilename
End Property

Property Let filename(ByVal sTheFile As String) '设置播放文件的名称
       mmOpen sTheFile
End Property

Property Get Wait() As Boolean
   Wait = bWait
End Property

Property Let Wait(bWaitValue As Boolean)      '设置是否等待触发
   bWait = bWaitValue
End Property

Property Get Length() As Single              '得到目前播放长度
   Dim nReturn As Long, nLength As Integer
   Dim sLength As String * 255
   If salias = "" Then
      Length = 0
      Exit Property
   End If
  nReturn = mciSendString("Status " & salias & " length", sLength, 255, 0)
  nLength = InStr(sLength, Chr$(0))
  Length = Val(Left$(sLength, nLength - 1))
End Property
Property Let Position(ByVal nPosition As Single)
    mmSeek nPosition
End Property

Property Get Position() As Single       '得到音乐文件长度的属性
   Dim nReturn As Integer, nLength As Integer
   Dim sPosition As String * 255
   If salias = "" Then Exit Property
   nReturn = mciSendString("Status " & salias & " position", sPosition, 255, 0)
   nLength = InStr(sPosition, Chr$(0))
   Position = Val(Left$(sPosition, nLength - 1))
End Property
Property Get Status() As String         '得到播放状态的属性
   Dim nReturn As Integer, nLength As Integer
   Dim sStatus As String * 255
   If salias = "" Then Exit Property
   nReturn = mciSendString("Status " & salias & " mode", sStatus, 255, 0)
   nLength = InStr(sStatus, Chr$(0))
   Status = Left$(sStatus, nLength - 1)
End Property

⌨️ 快捷键说明

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