📄 mp3player.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 cmdExit As System.Windows.Forms.Button
Public WithEvents cmdStop As System.Windows.Forms.Button
Public WithEvents cmdNext As System.Windows.Forms.Button
Public WithEvents cmdContinue As System.Windows.Forms.Button
Public WithEvents cmdPause As System.Windows.Forms.Button
Public WithEvents cmdPlay As System.Windows.Forms.Button
Public WithEvents Text1 As System.Windows.Forms.TextBox
Public WithEvents CommonDialog1 As AxMSComDlg.AxCommonDialog
Public WithEvents MediaPlayer1 As AxMediaPlayer.AxMediaPlayer
'注意:以下过程是 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.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.cmdExit = New System.Windows.Forms.Button()
Me.cmdStop = New System.Windows.Forms.Button()
Me.cmdPlay = New System.Windows.Forms.Button()
Me.MediaPlayer1 = New AxMediaPlayer.AxMediaPlayer()
Me.CommonDialog1 = New AxMSComDlg.AxCommonDialog()
Me.Text1 = New System.Windows.Forms.TextBox()
Me.cmdPause = New System.Windows.Forms.Button()
Me.cmdNext = New System.Windows.Forms.Button()
Me.cmdContinue = New System.Windows.Forms.Button()
CType(Me.MediaPlayer1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.CommonDialog1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'cmdExit
'
Me.cmdExit.BackColor = System.Drawing.SystemColors.Control
Me.cmdExit.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdExit.Location = New System.Drawing.Point(266, 93)
Me.cmdExit.Name = "cmdExit"
Me.cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdExit.Size = New System.Drawing.Size(104, 28)
Me.cmdExit.TabIndex = 7
Me.cmdExit.Text = "退出"
'
'cmdStop
'
Me.cmdStop.BackColor = System.Drawing.SystemColors.Control
Me.cmdStop.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdStop.Location = New System.Drawing.Point(143, 93)
Me.cmdStop.Name = "cmdStop"
Me.cmdStop.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdStop.Size = New System.Drawing.Size(104, 28)
Me.cmdStop.TabIndex = 6
Me.cmdStop.Text = "停止"
'
'cmdPlay
'
Me.cmdPlay.BackColor = System.Drawing.SystemColors.Control
Me.cmdPlay.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdPlay.ForeColor = System.Drawing.SystemColors.ControlDarkDark
Me.cmdPlay.Location = New System.Drawing.Point(20, 56)
Me.cmdPlay.Name = "cmdPlay"
Me.cmdPlay.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdPlay.Size = New System.Drawing.Size(104, 28)
Me.cmdPlay.TabIndex = 2
Me.cmdPlay.Text = "播放"
'
'MediaPlayer1
'
Me.MediaPlayer1.Location = New System.Drawing.Point(0, 168)
Me.MediaPlayer1.Name = "MediaPlayer1"
Me.MediaPlayer1.OcxState = CType(resources.GetObject("MediaPlayer1.OcxState"), System.Windows.Forms.AxHost.State)
Me.MediaPlayer1.Size = New System.Drawing.Size(46, 31)
Me.MediaPlayer1.TabIndex = 0
'
'CommonDialog1
'
Me.CommonDialog1.Enabled = True
Me.CommonDialog1.Location = New System.Drawing.Point(328, 93)
Me.CommonDialog1.Name = "CommonDialog1"
Me.CommonDialog1.OcxState = CType(resources.GetObject("CommonDialog1.OcxState"), System.Windows.Forms.AxHost.State)
Me.CommonDialog1.Size = New System.Drawing.Size(32, 32)
Me.CommonDialog1.TabIndex = 8
'
'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(16, 8)
Me.Text1.MaxLength = 0
Me.Text1.Name = "Text1"
Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Text1.Size = New System.Drawing.Size(360, 29)
Me.Text1.TabIndex = 1
Me.Text1.Text = "Text1"
'
'cmdPause
'
Me.cmdPause.BackColor = System.Drawing.SystemColors.Control
Me.cmdPause.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdPause.Location = New System.Drawing.Point(143, 56)
Me.cmdPause.Name = "cmdPause"
Me.cmdPause.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdPause.Size = New System.Drawing.Size(104, 28)
Me.cmdPause.TabIndex = 3
Me.cmdPause.Text = "暂停"
'
'cmdNext
'
Me.cmdNext.BackColor = System.Drawing.SystemColors.Control
Me.cmdNext.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdNext.Location = New System.Drawing.Point(20, 93)
Me.cmdNext.Name = "cmdNext"
Me.cmdNext.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdNext.Size = New System.Drawing.Size(104, 28)
Me.cmdNext.TabIndex = 5
Me.cmdNext.Text = "下一曲"
'
'cmdContinue
'
Me.cmdContinue.BackColor = System.Drawing.SystemColors.Control
Me.cmdContinue.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdContinue.Location = New System.Drawing.Point(266, 56)
Me.cmdContinue.Name = "cmdContinue"
Me.cmdContinue.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdContinue.Size = New System.Drawing.Size(104, 28)
Me.cmdContinue.TabIndex = 4
Me.cmdContinue.Text = "继续"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(394, 135)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdExit, Me.cmdStop, Me.cmdNext, Me.cmdContinue, Me.cmdPause, Me.cmdPlay, Me.Text1, Me.CommonDialog1, Me.MediaPlayer1})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.Location = New System.Drawing.Point(3, 22)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
Me.Text = "MP3Player......"
CType(Me.MediaPlayer1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.CommonDialog1, 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
Private Sub cmdContinue_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdContinue.Click
Text1.Focus()
MediaPlayer1.Play()
cmdPlay.Enabled = False
cmdPause.Enabled = True
cmdContinue.Enabled = False
End Sub
Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
MediaPlayer1.Stop()
End
End Sub
Private Sub cmdNext_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNext.Click
On Error GoTo NextErr '播放非m3u文件时只能播放单曲
Exit Sub
NextErr:
MsgBox("现在正在播放单曲,没有一下曲。", MsgBoxStyle.OKOnly, "出错信息")
End Sub
Private Sub cmdPause_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPause.Click
Text1.Focus()
MediaPlayer1.Pause()
cmdPause.Enabled = False
cmdContinue.Enabled = True
End Sub
Private Sub cmdPlay_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPlay.Click
Text1.Focus()
On Error GoTo handler
With CommonDialog1
.InitDir = VB6.GetPath
.Filter = "Midi Files(*.mid)|*.mid|MP3 Files(*.mp3)|*.mp3|Wave Filse(*.wav)|*.wav|(*.m3u)|*.m3u"
.FilterIndex = 2
.FileName = ""
.ShowOpen()
End With
MediaPlayer1.FileName = CommonDialog1.FileName
MediaPlayer1.Play()
Text1.Text = " 正在播放:" & CommonDialog1.FileName
cmdPlay.Enabled = False
cmdPause.Enabled = True
cmdContinue.Enabled = False
cmdStop.Enabled = True
Exit Sub
handler:
MsgBox("未选择媒体文件。", MsgBoxStyle.OKOnly, "错误信息")
End Sub
Private Sub cmdStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStop.Click
MediaPlayer1.Stop()
cmdPlay.Enabled = True
cmdPause.Enabled = False
cmdContinue.Enabled = False
cmdStop.Enabled = False
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
MediaPlayer1.Visible = False
cmdContinue.Enabled = False
cmdPause.Enabled = False
cmdStop.Enabled = False
Text1.Text = "本播放器支持各种音乐格式。谢谢使用。"
Text1.BackColor = System.Drawing.Color.Black
Text1.ForeColor = System.Drawing.Color.Yellow
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -