c#播放器代码,要求把播放文件放在listbox里面,然后双击能播放就可以了,高手帮个忙
2个回答
展开全部
//貌似答非所问了呢~
Public Class frmAudioPlayer
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
Friend WithEvents AxMMControl1 As AxMCI.AxMMControl
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ProgressBar2 As System.Windows.Forms.ProgressBar
Friend WithEvents AxMMControl2 As AxMCI.AxMMControl
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog2 As System.Windows.Forms.OpenFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmAudioPlayer))
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.AxMMControl1 = New AxMCI.AxMMControl
Me.Button1 = New System.Windows.Forms.Button
Me.ProgressBar2 = New System.Windows.Forms.ProgressBar
Me.AxMMControl2 = New AxMCI.AxMMControl
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.Button2 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.OpenFileDialog2 = New System.Windows.Forms.OpenFileDialog
CType(Me.AxMMControl1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.AxMMControl2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'ProgressBar1
'
Me.ProgressBar1.Location = New System.Drawing.Point(120, 8)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(216, 16)
Me.ProgressBar1.TabIndex = 0
'
'AxMMControl1
'
Me.AxMMControl1.Enabled = True
Me.AxMMControl1.Location = New System.Drawing.Point(24, 40)
Me.AxMMControl1.Name = "AxMMControl1"
Me.AxMMControl1.OcxState = CType(resources.GetObject("AxMMControl1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMMControl1.Size = New System.Drawing.Size(280, 22)
Me.AxMMControl1.TabIndex = 1
Me.AxMMControl1.Visible = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 48)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 2
Me.Button1.Text = "选择声音"
'
'ProgressBar2
'
Me.ProgressBar2.Location = New System.Drawing.Point(120, 88)
Me.ProgressBar2.Name = "ProgressBar2"
Me.ProgressBar2.Size = New System.Drawing.Size(216, 16)
Me.ProgressBar2.TabIndex = 3
'
'AxMMControl2
'
Me.AxMMControl2.Enabled = True
Me.AxMMControl2.Location = New System.Drawing.Point(32, 104)
Me.AxMMControl2.Name = "AxMMControl2"
Me.AxMMControl2.OcxState = CType(resources.GetObject("AxMMControl2.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMMControl2.Size = New System.Drawing.Size(280, 22)
Me.AxMMControl2.TabIndex = 4
Me.AxMMControl2.Visible = False
'
'Button2
'
Me.Button2.Enabled = False
Me.Button2.Location = New System.Drawing.Point(96, 48)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 24)
Me.Button2.TabIndex = 5
Me.Button2.Text = "重放"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 16)
Me.Label1.TabIndex = 6
Me.Label1.Text = "声音播放进度:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(0, 88)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = "背景音乐播放进度:"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(160, 48)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(104, 24)
Me.Button3.TabIndex = 8
Me.Button3.Text = "选择背景音乐"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(272, 48)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 24)
Me.Button4.TabIndex = 9
Me.Button4.Text = "退出"
'
'frmAudioPlayer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(344, 118)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.AxMMControl2)
Me.Controls.Add(Me.ProgressBar2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.AxMMControl1)
Me.Controls.Add(Me.ProgressBar1)
Me.Name = "frmAudioPlayer"
Me.Text = "音频播放器"
CType(Me.AxMMControl1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxMMControl2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AxMMControl2_Done(ByVal sender As Object, ByVal e As AxMCI.DmciEvents_DoneEvent) Handles AxMMControl2.Done
If (AxMMControl2.Position = AxMMControl2.Length) Then '如果播放到文件尾,则重新播放
AxMMControl2.Command = "Prev" '回到文件头
AxMMControl2.Command = "Play" '重新播放
End If
End Sub
Private Sub AxMMControl2_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl2.StatusUpdate
ProgressBar2.Value = AxMMControl2.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
If (OpenFileDialog1.FileName <> "") Then
AxMMControl1.Command = "Close" '关闭播放朗诵声音的多媒体设备
AxMMControl1.Notify = True '
AxMMControl1.FileName = OpenFileDialog1.FileName '
AxMMControl1.Command = "Open" '打开多媒体设备
AxMMControl1.TimeFormat = 4
ProgressBar1.Minimum = 0 '设置进度条的最小值
ProgressBar1.Maximum = AxMMControl1.Length '设置进度条的最大值
AxMMControl1.Command = "Play" '播放
Button2.Enabled = True '“重放”按钮可用
End If
End Sub
Private Sub AxMMControl1_BackClick(ByVal sender As System.Object, ByVal e As AxMCI.DmciEvents_BackClickEvent) Handles AxMMControl1.BackClick
End Sub
Private Sub AxMMControl1_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl1.StatusUpdate
ProgressBar1.Value = AxMMControl1.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog2.ShowDialog()
If (OpenFileDialog2.FileName <> "") Then
AxMMControl2.Command = "Close" '关闭播放背景音乐的多媒体设备
AxMMControl2.Notify = True '
AxMMControl2.FileName = OpenFileDialog2.FileName '
AxMMControl2.Command = "Open" '打开播放背景音乐的多媒体设备
AxMMControl2.TimeFormat = 3 '设置时间格式
ProgressBar2.Minimum = 0 '设置进度条的最小值
ProgressBar2.Maximum = AxMMControl2.Length '设置进度条的最大值
AxMMControl2.Command = "Play" '播放
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AxMMControl1.Command = "Prev" '回到文件头
AxMMControl1.Command = "Play" '重新播放
ProgressBar1.Value = AxMMControl1.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Application.Exit() '退出应用程序
End Sub
Private Sub frmAudioPlayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxMMControl2.Notify = True
AxMMControl2.Command = "Close" '关闭播放背景音乐的多媒体设备
AxMMControl2.FileName = Application.StartupPath + "\1.mid" '设置背景音乐文件名
AxMMControl2.Command = "Open" '打开多媒体设备
AxMMControl2.TimeFormat = 3
ProgressBar2.Minimum = 0 '设置进度条的最小值
ProgressBar2.Maximum = AxMMControl2.Length '设置进度条的最大值
AxMMControl2.Command = "Play" '播放背景音尔
OpenFileDialog1.Filter = "声波文件(*.WAV)|*.WAV" '只能选出WAV文件
OpenFileDialog2.Filter = "音乐文件(*.MID)|*.mid" '只能选出MID文件
OpenFileDialog1.InitialDirectory = Application.StartupPath '初始目录为应用程序启动目录
OpenFileDialog2.InitialDirectory = Application.StartupPath '初始目录为应用程序启动目录
End Sub
End Class
Public Class frmAudioPlayer
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
Friend WithEvents AxMMControl1 As AxMCI.AxMMControl
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ProgressBar2 As System.Windows.Forms.ProgressBar
Friend WithEvents AxMMControl2 As AxMCI.AxMMControl
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog2 As System.Windows.Forms.OpenFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmAudioPlayer))
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
Me.AxMMControl1 = New AxMCI.AxMMControl
Me.Button1 = New System.Windows.Forms.Button
Me.ProgressBar2 = New System.Windows.Forms.ProgressBar
Me.AxMMControl2 = New AxMCI.AxMMControl
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.Button2 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.OpenFileDialog2 = New System.Windows.Forms.OpenFileDialog
CType(Me.AxMMControl1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.AxMMControl2, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'ProgressBar1
'
Me.ProgressBar1.Location = New System.Drawing.Point(120, 8)
Me.ProgressBar1.Name = "ProgressBar1"
Me.ProgressBar1.Size = New System.Drawing.Size(216, 16)
Me.ProgressBar1.TabIndex = 0
'
'AxMMControl1
'
Me.AxMMControl1.Enabled = True
Me.AxMMControl1.Location = New System.Drawing.Point(24, 40)
Me.AxMMControl1.Name = "AxMMControl1"
Me.AxMMControl1.OcxState = CType(resources.GetObject("AxMMControl1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMMControl1.Size = New System.Drawing.Size(280, 22)
Me.AxMMControl1.TabIndex = 1
Me.AxMMControl1.Visible = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 48)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 2
Me.Button1.Text = "选择声音"
'
'ProgressBar2
'
Me.ProgressBar2.Location = New System.Drawing.Point(120, 88)
Me.ProgressBar2.Name = "ProgressBar2"
Me.ProgressBar2.Size = New System.Drawing.Size(216, 16)
Me.ProgressBar2.TabIndex = 3
'
'AxMMControl2
'
Me.AxMMControl2.Enabled = True
Me.AxMMControl2.Location = New System.Drawing.Point(32, 104)
Me.AxMMControl2.Name = "AxMMControl2"
Me.AxMMControl2.OcxState = CType(resources.GetObject("AxMMControl2.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxMMControl2.Size = New System.Drawing.Size(280, 22)
Me.AxMMControl2.TabIndex = 4
Me.AxMMControl2.Visible = False
'
'Button2
'
Me.Button2.Enabled = False
Me.Button2.Location = New System.Drawing.Point(96, 48)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 24)
Me.Button2.TabIndex = 5
Me.Button2.Text = "重放"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 16)
Me.Label1.TabIndex = 6
Me.Label1.Text = "声音播放进度:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(0, 88)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(120, 16)
Me.Label2.TabIndex = 7
Me.Label2.Text = "背景音乐播放进度:"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(160, 48)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(104, 24)
Me.Button3.TabIndex = 8
Me.Button3.Text = "选择背景音乐"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(272, 48)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(64, 24)
Me.Button4.TabIndex = 9
Me.Button4.Text = "退出"
'
'frmAudioPlayer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(344, 118)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.AxMMControl2)
Me.Controls.Add(Me.ProgressBar2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.AxMMControl1)
Me.Controls.Add(Me.ProgressBar1)
Me.Name = "frmAudioPlayer"
Me.Text = "音频播放器"
CType(Me.AxMMControl1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxMMControl2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub AxMMControl2_Done(ByVal sender As Object, ByVal e As AxMCI.DmciEvents_DoneEvent) Handles AxMMControl2.Done
If (AxMMControl2.Position = AxMMControl2.Length) Then '如果播放到文件尾,则重新播放
AxMMControl2.Command = "Prev" '回到文件头
AxMMControl2.Command = "Play" '重新播放
End If
End Sub
Private Sub AxMMControl2_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl2.StatusUpdate
ProgressBar2.Value = AxMMControl2.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
If (OpenFileDialog1.FileName <> "") Then
AxMMControl1.Command = "Close" '关闭播放朗诵声音的多媒体设备
AxMMControl1.Notify = True '
AxMMControl1.FileName = OpenFileDialog1.FileName '
AxMMControl1.Command = "Open" '打开多媒体设备
AxMMControl1.TimeFormat = 4
ProgressBar1.Minimum = 0 '设置进度条的最小值
ProgressBar1.Maximum = AxMMControl1.Length '设置进度条的最大值
AxMMControl1.Command = "Play" '播放
Button2.Enabled = True '“重放”按钮可用
End If
End Sub
Private Sub AxMMControl1_BackClick(ByVal sender As System.Object, ByVal e As AxMCI.DmciEvents_BackClickEvent) Handles AxMMControl1.BackClick
End Sub
Private Sub AxMMControl1_StatusUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxMMControl1.StatusUpdate
ProgressBar1.Value = AxMMControl1.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog2.ShowDialog()
If (OpenFileDialog2.FileName <> "") Then
AxMMControl2.Command = "Close" '关闭播放背景音乐的多媒体设备
AxMMControl2.Notify = True '
AxMMControl2.FileName = OpenFileDialog2.FileName '
AxMMControl2.Command = "Open" '打开播放背景音乐的多媒体设备
AxMMControl2.TimeFormat = 3 '设置时间格式
ProgressBar2.Minimum = 0 '设置进度条的最小值
ProgressBar2.Maximum = AxMMControl2.Length '设置进度条的最大值
AxMMControl2.Command = "Play" '播放
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AxMMControl1.Command = "Prev" '回到文件头
AxMMControl1.Command = "Play" '重新播放
ProgressBar1.Value = AxMMControl1.Position '用多媒体文件的当前位置更新进度条值
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Application.Exit() '退出应用程序
End Sub
Private Sub frmAudioPlayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxMMControl2.Notify = True
AxMMControl2.Command = "Close" '关闭播放背景音乐的多媒体设备
AxMMControl2.FileName = Application.StartupPath + "\1.mid" '设置背景音乐文件名
AxMMControl2.Command = "Open" '打开多媒体设备
AxMMControl2.TimeFormat = 3
ProgressBar2.Minimum = 0 '设置进度条的最小值
ProgressBar2.Maximum = AxMMControl2.Length '设置进度条的最大值
AxMMControl2.Command = "Play" '播放背景音尔
OpenFileDialog1.Filter = "声波文件(*.WAV)|*.WAV" '只能选出WAV文件
OpenFileDialog2.Filter = "音乐文件(*.MID)|*.mid" '只能选出MID文件
OpenFileDialog1.InitialDirectory = Application.StartupPath '初始目录为应用程序启动目录
OpenFileDialog2.InitialDirectory = Application.StartupPath '初始目录为应用程序启动目录
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询