Advance Media Player Code
Advance Media Player Code in vb .net
***********************************************
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
Private Const APPCOMMAND_VOLUME_MUTE As Integer = &H80000
Private Const APPCOMMAND_VOLUME_UP As Integer = &HA0000
Private Const APPCOMMAND_VOLUME_DOWN As Integer = &H90000
Private Const WM_APPCOMMAND As Integer = &H319
Dim TrcBarValue As Integer
<DllImport("user32.dll")> Public Shared Function SendMessageW(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
Dim track As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
ListBox1.Items.Clear()
ListBox2.Items.Clear()
AxWindowsMediaPlayer1.URL = (OpenFileDialog1.FileName)
ToolStripStatusLabel1.Text = "Playing"
Timer1.Enabled = True
End If
For Each track In OpenFileDialog1.FileNames
ListBox2.Items.Add(System.IO.Path.GetFileName(track))
Next
For Each track In OpenFileDialog1.FileNames
ListBox1.Items.Add(track)
Next
ListBox2.SelectedIndex = 0
ListBox1.SelectedIndex = 0
Label1.Text = " Total Song " & ListBox2.Items.Count
Me.Text = System.IO.Path.GetFileName(CStr(ListBox1.SelectedItem))
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label2.Text = Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
Label3.Text = Me.AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString
TrackBar3.Minimum = 0
Me.TrackBar3.Value = Convert.ToInt32((AxWindowsMediaPlayer1.Ctlcontrols.currentPosition / AxWindowsMediaPlayer1.currentMedia.duration) * 100)
If TrackBar3.Value = TrackBar3.Maximum Then
AxWindowsMediaPlayer1.Ctlcontrols.next()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TrackBar1.Value = 5
End Sub
Private Sub TrackBar1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
TrcBarValue = TrackBar1.Value
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Dim TrcBarDirection As Integer = TrackBar1.Value
If TrackBar1.Value > TrcBarValue Then
For TrcBarDirection = 0 To TrcBarDirection
SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, New IntPtr(APPCOMMAND_VOLUME_UP))
Next
Else : For TrcBarDirection = 0 To TrcBarValue
SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, New IntPtr(APPCOMMAND_VOLUME_DOWN))
Next
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, New IntPtr(APPCOMMAND_VOLUME_MUTE))
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteToolStripMenuItem.Click
AxWindowsMediaPlayer1.settings.mute = True
End Sub
Private Sub UpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpToolStripMenuItem.Click
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 5
End Sub
Private Sub DownToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownToolStripMenuItem.Click
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume - 5
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If AxWindowsMediaPlayer1.settings.mute = True Then
AxWindowsMediaPlayer1.settings.mute = False
Else
AxWindowsMediaPlayer1.settings.mute = True
End If
End Sub
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
If TrackBar2.Value = 0 Then
AxWindowsMediaPlayer1.settings.volume = Integer.MinValue
ElseIf TrackBar2.Value = 1 Then
AxWindowsMediaPlayer1.settings.volume = CInt(AxWindowsMediaPlayer1.settings.mute) + 10
ElseIf TrackBar2.Value = 2 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 3 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 4 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 5 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 6 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 7 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 8 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 9 Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume + 10
ElseIf TrackBar2.Value = 10 Then
AxWindowsMediaPlayer1.settings.volume = Integer.MaxValue
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
AxWindowsMediaPlayer1.Ctlcontrols.play()
ToolStripStatusLabel1.Text = "Playing"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
AxWindowsMediaPlayer1.Ctlcontrols.pause()
ToolStripStatusLabel1.Text = "Pause"
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
AxWindowsMediaPlayer1.Ctlcontrols.previous()
Try
ListBox1.SelectedIndex += -1
ListBox2.SelectedIndex += -1
AxWindowsMediaPlayer1.URL = CStr(ListBox1.SelectedItem)
Me.Text = System.IO.Path.GetFileName(CStr(ListBox1.SelectedItem))
Catch ex As Exception
MsgBox("No Song Selected")
End Try
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
AxWindowsMediaPlayer1.Ctlcontrols.next()
Try
ListBox1.SelectedIndex += +1
ListBox2.SelectedIndex += +1
AxWindowsMediaPlayer1.URL = CStr(ListBox1.SelectedItem)
Me.Text = System.IO.Path.GetFileName(CStr(ListBox1.SelectedItem))
Catch ex As Exception
MsgBox("No Song Selected")
End Try
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
AxWindowsMediaPlayer1.Ctlcontrols.stop()
ToolStripStatusLabel1.Text = "Stop"
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
AxWindowsMediaPlayer1.Ctlcontrols.fastReverse()
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
AxWindowsMediaPlayer1.Ctlcontrols.fastForward()
End Sub
Private Sub TrackBar3_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar3.ValueChanged
If TrackBar3.Value = TrackBar3.Maximum Then
Button7.PerformClick()
End If
End Sub
Private Sub TrackBar3_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar3.Scroll
Try
If Me.AxWindowsMediaPlayer1.currentMedia.duration <> 0 Then
Dim duration As Double = Me.TrackBar1.Value / Me.TrackBar1.Maximum
Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = Me.AxWindowsMediaPlayer1.currentMedia.duration * duration
Else : Me.TrackBar1.Value = 0
End If
Catch ex As Exception
End Try
End Sub
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If TrackBar3.Value = TrackBar3.Maximum Then
AxWindowsMediaPlayer1.Ctlcontrols.next()
End If
End Sub
Private Sub AxWindowsMediaPlayer1_PlaylistChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlaylistChangeEvent) Handles AxWindowsMediaPlayer1.PlaylistChange
If TrackBar3.Value = TrackBar3.Maximum Then
AxWindowsMediaPlayer1.Ctlcontrols.next()
End If
End Sub
Private Sub AxWindowsMediaPlayer1_StatusChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWindowsMediaPlayer1.StatusChange
If TrackBar3.Value = TrackBar3.Maximum Then
AxWindowsMediaPlayer1.Ctlcontrols.next()
End If
End Sub
Private Sub TrackBar2_Move(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Move
If CBool(TrackBar2.RightToLeft) Then
AxWindowsMediaPlayer1.settings.volume = AxWindowsMediaPlayer1.settings.volume - 10
End If
End Sub
End Class
***************** End Project ************************
Comments
Post a Comment