Sunday, June 12, 2011

Audio Player Using AxWindowsMediaPlayer in VB.Net



Public Class Audio_Player
#Region "All Controls"
    Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        Try
            Call GetOpenMedia()
            TrackBar1.Maximum = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration
            Label2.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString
            Timer1.Interval = 100
            Timer1.Enabled = True
        Catch ex As Exception

        End Try

    End Sub

    Private Sub OpenToolStripMenuItem_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        Try
            Call GetOpenMedia()
            TrackBar1.Maximum = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration
            Label2.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString
            Timer1.Interval = 100
            Timer1.Enabled = True
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPlay.Click
        Try
            AxWindowsMediaPlayer1.Ctlcontrols.play()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnPause_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Try
            AxWindowsMediaPlayer1.Ctlcontrols.pause()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStop.Click
        Try
            Label1.Text = "00:00"
            AxWindowsMediaPlayer1.Ctlcontrols.stop()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub GetOpenMedia()
        Play_List.DataGridView1.Rows.Clear()
        Dim OpenMedia As New OpenFileDialog
        OpenMedia.InitialDirectory = System.Environment.SpecialFolder.CommonMusic
        OpenMedia.FileName = ""
        OpenMedia.Multiselect = False
        OpenMedia.Filter = "Audio Files (*.wav;*.snd;*.au;*.aif;*.aifc;*.aiff;*.wma;*.mp2;*.mp3;*.adts;*.adt;*.acc)|*.wav;*.snd;*.au;*.aif;*.aifc;*.aiff;*.wma;*.mp2;*.mp3;*.adts;*.adt;*.acc"
        If OpenMedia.ShowDialog() = DialogResult.OK Then
            Play_List.DataGridView1.Rows.Add(OpenMedia.FileName)
            AxWindowsMediaPlayer1.URL = OpenMedia.FileName
        End If
    End Sub

    Private Sub OpenFilesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OpenFilesToolStripMenuItem.Click
        Try

            Dim OpenMedia As New OpenFileDialog
            OpenMedia.InitialDirectory = System.Environment.SpecialFolder.CommonMusic
            OpenMedia.FileName = ""
            OpenMedia.Multiselect = True
            OpenMedia.Filter = "Audio Files (*.wav;*.snd;*.au;*.aif;*.aifc;*.aiff;*.wma;*.mp2;*.mp3;*.adts;*.adt;*.acc)|*.wav;*.snd;*.au;*.aif;*.aifc;*.aiff;*.wma;*.mp2;*.mp3;*.adts;*.adt;*.acc"
            If OpenMedia.ShowDialog() = DialogResult.OK Then
                'For Each str1 As String In OpenMedia.FileNames
                '    Play_List.ListBox1.Items.Add(str1)
                'Next
                For Each Str As String In OpenMedia.FileNames
                    Play_List.DataGridView1.Rows.Add(Str)
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Audio_Player_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        tmrFR.Interval = 100
        TrackBar2.Value = 50
        ProgressBar1.Value = TrackBar2.Value
        AxWindowsMediaPlayer1.settings.volume = TrackBar2.Value
        Label3.Text = "Volume: " & TrackBar2.Value & " %"
        AxWindowsMediaPlayer1.Visible = False
        Timer1.Interval = 100
        If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
            Timer1.Enabled = True
        Else
            Timer1.Enabled = False
        End If
        Play_List.Visible = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            TrackBar1.Maximum = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration
            Label1.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
            TrackBar1.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
            Label2.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString

        Catch ex As Exception

        End Try
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Try
            AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = TrackBar1.Value
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub TrackBar2_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        Try
            AxWindowsMediaPlayer1.settings.volume = TrackBar2.Value
            ProgressBar1.Value = TrackBar2.Value
            Label3.Text = "Volume: " & TrackBar2.Value & " %"
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnMuteOnOff_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMuteOnOff.Click
        Try
            If AxWindowsMediaPlayer1.settings.mute = False Then
                btnMuteOnOff.FlatStyle = FlatStyle.Flat
                AxWindowsMediaPlayer1.settings.mute = True
            Else
                AxWindowsMediaPlayer1.settings.mute = False
                btnMuteOnOff.FlatStyle = FlatStyle.Standard
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub PlayListToolStripMenuItem_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PlayListToolStripMenuItem.Click
        If Play_List.Visible = False Then
            Play_List.Visible = True
        Else
            Play_List.Visible = False
        End If
    End Sub

    Private Sub btnFastForword_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFastForword.Click
        Try
            AxWindowsMediaPlayer1.Ctlcontrols.fastForward()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnFastReverse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFastReverse.Click
        Try
            tmrFR.Enabled = True
        Catch ex As Exception

        End Try
    End Sub

    Private Sub tmrFR_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrFR.Tick
        Try
            If Not AxWindowsMediaPlayer1.Ctlcontrols.currentPosition <= 0 Then
                AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition - 1
                If AxWindowsMediaPlayer1.Ctlcontrols.currentPosition <= 0 Then
                    tmrFR.Enabled = False
                    AxWindowsMediaPlayer1.Ctlcontrols.stop()
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub
#End Region

End Class




Monday, February 14, 2011

Simple way to create transparent borders like Vista/windows 7 in XP with vb.net It's a trick


Simple way to create transparent borders like Vista/windows 7 in XP with vb.net
It’s a trick.
First you need two forms that is form1(default form of project) and add new form(it will be form2)
then set color to form1(as you like) and set its opacity to 80%
Make sure that both forms  Formborderstyle set as None
then
put the following code into form1:
Public Class Form1
    Dim xx, yy As Integer
    Dim iMouseDown As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.Visible = True
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        iMouseDown = 1
        xx = e.X : yy = e.Y
        Me.Cursor = Cursors.NoMove2D
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If iMouseDown = 1 Then
            If e.X > xx Then
                Me.Left = Me.Left + 1
                Form2.Left = Form2.Left + 1
            End If
            If e.X < xx Then
                Me.Left = Me.Left - 1
                Form2.Left = Form2.Left - 1
            End If
            If e.Y > yy Then
                Me.Top = Me.Top + 1
                Form2.Top = Form2.Top + 1
            End If
            If e.Y < yy Then
                Me.Top = Me.Top - 1
                Form2.Top = Form2.Top - 1
            End If
        End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        iMouseDown = 0
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub frmClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles frmClose.Click
        Application.Exit()
    End Sub
End Class
after that put following code into form2 load event:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Height = Form1.Height - 60
        Me.Left = Me.Left + 10
        Me.Width = Me.Width - 20
    End Sub
You can add some controls to form2 like:


now Run Project

Thank you

Wednesday, January 19, 2011

ProgressBar with Voice








'Make sure for this one you already installed a Microsoft Text To Speach Lib/DSK on your Computer
If not then download from :




Imports SpeechLib
Public Class Form1
    Dim voice As SpeechLib.ISpeechVoice
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000
        Timer1.Enabled = True
        voice = New SpeechLib.SpVoice
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value = ProgressBar1.Value + 1
        Label1.Text = ProgressBar1.Value & " % Complete"
        If ProgressBar1.Value = 25 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 50 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 75 Then
            voice.Speak(ProgressBar1.Value & " % complete")
        End If
        If ProgressBar1.Value = 100 Then
            voice.Speak(ProgressBar1.Value & " % loading complete")
        End If
        If ProgressBar1.Value = 100 Then
            Timer1.Enabled = False
        End If
    End Sub
End Class