當前位置:編程學習大全網 - 源碼下載 - c#播放器代碼,要求把播放文件放在listbox裏面,然後雙擊能播放就可以了,高手幫個忙

c#播放器代碼,要求把播放文件放在listbox裏面,然後雙擊能播放就可以了,高手幫個忙

//貌似答非所問了呢~

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

  • 上一篇:華潤雪花啤酒有限公司股票代碼是什麽?
  • 下一篇:雲公式源代碼
  • copyright 2024編程學習大全網