📄 testmm.vb
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
Public Sub New()
MyBase.New()
If m_vb6FormDefInstance Is Nothing Then
If m_InitializingDefInstance Then
m_vb6FormDefInstance = Me
Else
Try
'对于启动窗体,所创建的第一个实例为默认实例。
If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
m_vb6FormDefInstance = Me
End If
Catch
End Try
End If
End If
'此调用是 Windows 窗体设计器所必需的。
InitializeComponent()
End Sub
'窗体重写处置,以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
Private components As System.ComponentModel.IContainer
'Windows 窗体设计器所必需的
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents Slider1 As AxComctlLib.AxSlider
Public WithEvents Command4 As System.Windows.Forms.Button
Public WithEvents Timer1 As System.Windows.Forms.Timer
Public WithEvents Text1 As System.Windows.Forms.TextBox
Public WithEvents Command3 As System.Windows.Forms.Button
Public WithEvents Command2 As System.Windows.Forms.Button
Public WithEvents CommonDialog1 As AxMSComDlg.AxCommonDialog
Public WithEvents Command1 As System.Windows.Forms.Button
Public WithEvents Label3 As System.Windows.Forms.Label
Public WithEvents Label2 As System.Windows.Forms.Label
Public WithEvents Label1 As System.Windows.Forms.Label
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器来修改它。
'不要使用代码编辑器来修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Label3 = New System.Windows.Forms.Label()
Me.Command1 = New System.Windows.Forms.Button()
Me.Command3 = New System.Windows.Forms.Button()
Me.Command2 = New System.Windows.Forms.Button()
Me.CommonDialog1 = New AxMSComDlg.AxCommonDialog()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.Slider1 = New AxComctlLib.AxSlider()
Me.Command4 = New System.Windows.Forms.Button()
Me.Text1 = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.Slider1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Label3
'
Me.Label3.BackColor = System.Drawing.SystemColors.Control
Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
Me.Label3.ForeColor = System.Drawing.Color.Black
Me.Label3.Location = New System.Drawing.Point(16, 128)
Me.Label3.Name = "Label3"
Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label3.Size = New System.Drawing.Size(114, 29)
Me.Label3.TabIndex = 8
Me.Label3.Text = "Label3"
'
'Command1
'
Me.Command1.BackColor = System.Drawing.SystemColors.ScrollBar
Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Command1.Location = New System.Drawing.Point(20, 56)
Me.Command1.Name = "Command1"
Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command1.Size = New System.Drawing.Size(166, 28)
Me.Command1.TabIndex = 0
Me.Command1.Text = "Load and play a file"
'
'Command3
'
Me.Command3.BackColor = System.Drawing.SystemColors.ScrollBar
Me.Command3.Cursor = System.Windows.Forms.Cursors.Default
Me.Command3.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.Command3.Location = New System.Drawing.Point(287, 56)
Me.Command3.Name = "Command3"
Me.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command3.Size = New System.Drawing.Size(62, 28)
Me.Command3.TabIndex = 2
Me.Command3.Text = "Stop"
'
'Command2
'
Me.Command2.BackColor = System.Drawing.SystemColors.ScrollBar
Me.Command2.Cursor = System.Windows.Forms.Cursors.Default
Me.Command2.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.Command2.Location = New System.Drawing.Point(205, 56)
Me.Command2.Name = "Command2"
Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command2.Size = New System.Drawing.Size(63, 28)
Me.Command2.TabIndex = 1
Me.Command2.Text = "Pause"
'
'CommonDialog1
'
Me.CommonDialog1.Enabled = True
Me.CommonDialog1.Location = New System.Drawing.Point(430, 120)
Me.CommonDialog1.Name = "CommonDialog1"
Me.CommonDialog1.OcxState = CType(resources.GetObject("CommonDialog1.OcxState"), System.Windows.Forms.AxHost.State)
Me.CommonDialog1.Size = New System.Drawing.Size(26, 26)
Me.CommonDialog1.TabIndex = 6
'
'Timer1
'
Me.Timer1.Interval = 250
'
'Slider1
'
Me.Slider1.Location = New System.Drawing.Point(10, 93)
Me.Slider1.Name = "Slider1"
Me.Slider1.OcxState = CType(resources.GetObject("Slider1.OcxState"), System.Windows.Forms.AxHost.State)
Me.Slider1.Size = New System.Drawing.Size(442, 28)
Me.Slider1.TabIndex = 4
'
'Command4
'
Me.Command4.BackColor = System.Drawing.SystemColors.Control
Me.Command4.Cursor = System.Windows.Forms.Cursors.Default
Me.Command4.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.Command4.Location = New System.Drawing.Point(369, 56)
Me.Command4.Name = "Command4"
Me.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Command4.Size = New System.Drawing.Size(62, 28)
Me.Command4.TabIndex = 5
Me.Command4.Text = "Exit"
'
'Text1
'
Me.Text1.AcceptsReturn = True
Me.Text1.AutoSize = False
Me.Text1.BackColor = System.Drawing.Color.Black
Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam
Me.Text1.ForeColor = System.Drawing.Color.Yellow
Me.Text1.Location = New System.Drawing.Point(20, 9)
Me.Text1.MaxLength = 0
Me.Text1.Name = "Text1"
Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Text1.Size = New System.Drawing.Size(432, 29)
Me.Text1.TabIndex = 3
Me.Text1.Text = "Text1"
'
'Label1
'
Me.Label1.BackColor = System.Drawing.SystemColors.Control
Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
Me.Label1.ForeColor = System.Drawing.Color.Black
Me.Label1.Location = New System.Drawing.Point(136, 128)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(112, 29)
Me.Label1.TabIndex = 6
Me.Label1.Text = "Label1"
'
'Label2
'
Me.Label2.BackColor = System.Drawing.SystemColors.Control
Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
Me.Label2.ForeColor = System.Drawing.Color.Black
Me.Label2.Location = New System.Drawing.Point(264, 128)
Me.Label2.Name = "Label2"
Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label2.Size = New System.Drawing.Size(226, 29)
Me.Label2.TabIndex = 7
Me.Label2.Text = "Label2"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.SystemColors.ScrollBar
Me.ClientSize = New System.Drawing.Size(460, 143)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Slider1, Me.Command4, Me.Text1, Me.Command3, Me.Command2, Me.CommonDialog1, Me.Command1, Me.Label3, Me.Label2, Me.Label1})
Me.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Location = New System.Drawing.Point(3, 22)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.Text = "MIDIPlayer "
CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.Slider1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
#Region "升级支持"
Private Shared m_vb6FormDefInstance As Form1
Private Shared m_InitializingDefInstance As Boolean
Public Shared Property DefInstance() As Form1
Get
If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
m_InitializingDefInstance = True
m_vb6FormDefInstance = New Form1()
m_InitializingDefInstance = False
End If
DefInstance = m_vb6FormDefInstance
End Get
Set
m_vb6FormDefInstance = Value
End Set
End Property
#End Region
Dim Multimedia As Mmedia = New Mmedia ' 定义一个对象
Dim NewPosition As Single
Dim DisplayingInfo As String
Dim CrossNum As Short
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click ' 这个过程打开并播放一个多媒体文件
With CommonDialog1
.Filter = "WaveAudio (*.wav)|*.wav|Midi (*.mid)|*.mid|Video files (*.avi)|*.avi"
.FilterIndex = 2
.ShowOpen()
End With
If CommonDialog1.FileName <> "" Then
Multimedia.mmClose()
Multimedia.mmOpen(CommonDialog1.FileName)
Timer1.Enabled = True ' 使计时器开始计时
Slider1.Min = 0 ' 设置Slider1的值域
Slider1.Max = Multimedia.Length ' 设置Slider1的值域
Multimedia.mmPlay()
NewPosition = 0
DisplayingInfo = "正在播放:" & CommonDialog1.FileName & ""
Text1.Text = DisplayingInfo
Label3.Text = "总长度" & Str(Multimedia.Length)
End If
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click ' 这个过程在播放和暂停之间切换
If Command2.Text = "Pause" Then
Multimedia.mmPause()
Timer1.Enabled = False ' 当暂停播放时,计时器Timer1也停止计时
Command2.Text = "Continue"
Else
Timer1.Enabled = True
Multimedia.mmPlay()
Command2.Text = "Pause"
End If
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click '这个过程在播放、停止和重播之间切换
Select Case Command3.Text
Case "Stop"
Multimedia.mmStop()
Command3.Text = "Play"
Timer1.Enabled = False
Case "Play"
Multimedia.mmPlay()
Command3.Text = "Stop"
Timer1.Enabled = True
Case "Replay"
Multimedia.mmSeek(0)
Multimedia.mmPlay()
Command3.Text = "Stop"
Text1.Text = DisplayingInfo
Timer1.Enabled = True
End Select
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click '这个过程用以退出程序
Multimedia.mmClose()
End
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load ' 这个过程用以初始化有关变量
NewPosition = 0
CrossNum = 0
Slider1.SelectRange = True
Label1.Text = ""
Label2.Text = ""
Label3.Text = ""
Text1.Text = "请选择歌曲"
End Sub
'UPGRADE_WARNING: Form 事件 Form1.Unload 具有新的行为。 单击以获得更多信息:ms-help://MS.MSDNVS/vbcon/html/vbup2065.htm
Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
Multimedia.mmClose()
End Sub
Private Sub Slider1_MouseDownEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxComctlLib.ISliderEvents_MouseDownEvent) Handles Slider1.MouseDownEvent
If eventArgs.Shift = 1 Then
'Multimedia.mmStop
Timer1.Enabled = False
'Slider1.SelStart = Slider1.Value
'将先前的 SelLength (如果有)设置为 0.
'Slider1.SelLength = 0
End If
End Sub
Private Sub Slider1_MouseUpEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxComctlLib.ISliderEvents_MouseUpEvent) Handles Slider1.MouseUpEvent
If eventArgs.Shift = 1 Then
NewPosition = Slider1.Value
Label1.Text = CStr(Slider1.Value)
Multimedia.mmSeek(NewPosition)
Multimedia.mmPlay()
Timer1.Enabled = True
Else
Slider1.SelLength = 0
End If
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick ' 这个过程定时产生系统状态更新事件
CrossNum = (CrossNum + 1) Mod 26
If CrossNum >= 24 Then
Label2.Text = ""
End If
Label2.Text = Label2.Text & "*"
Label1.Text = "播放到 " & CStr(Multimedia.Position)
Slider1.Value = Multimedia.Position
If Multimedia.Position = Multimedia.Length Then
Text1.Text = "请选择歌曲"
Command3.Text = "Replay"
Label1.Text = ""
Label2.Text = ""
Label3.Text = ""
Timer1.Enabled = False
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -