Author Topic: Direct bass : Vb.net (vb2008, vb2010, vb6, vc#, vc++, devC++, delphi, AutoIt)  (Read 182548 times)

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #125 on: 7 Feb '14 - 11:58 »
Bass Uti ;D

LevelMeter, 1 channel and 2 Channel

Code: [Select]
Public Function LevelMeterL(ByVal handle As Integer) As Integer
        On Error Resume Next
        Dim v_Lev As Integer = BASS_ChannelGetLevel(handle)
        Return LowWord32(v_Lev)
    End Function
    Public Function LevelMeterR(ByVal handle As Integer) As Integer
        On Error Resume Next
        Dim v_Lev As Integer = BASS_ChannelGetLevel(handle)
        Return HighWord32(v_Lev)
    End Function
    Public Function LevelMeterLR(ByVal handle As Integer, ByVal ctlProgressL As ProgressBar, ByVal ctlProgressR As ProgressBar, ByVal ctlTimer As Timer) As Boolean
        On Error Resume Next
        ctlTimer.Interval = 35
        ctlProgressL.Maximum = 32768
        ctlProgressL.Value = LevelMeterL(handle)
        ctlProgressR.Maximum = 32768
        ctlProgressR.Value = LevelMeterR(handle)
    End Function
    Public Function LowWord32(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function
    Public Function HighWord32(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #126 on: 7 Feb '14 - 17:19 »
Visuals Mod ;D

Spectrum LinePeak
Code: [Select]
Public Module Visuals
    Private _a As Single() : Private _b As Single() : Private c As Boolean
    Private d As Integer : Private e As Integer : Private f As Integer
    Private g As Integer : Private h As BASSData : Private i As Integer
    Private j As Double : Private k As Boolean
    Sub New()
        _a = New Single(2047) {} : _b = New Single(2047) {}
        d = 9 : e = 4 : f = 4096 : g = 2047
        h = BASSData.BASS_DATA_FFT2048 : i = 2047 : j = 1
    End Sub
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Public Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer
    End Function
    '<Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    'Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Short(), ByVal length As Integer) As Integer
    'End Function
    '<Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    'Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Integer(), ByVal length As Integer) As Integer
    'End Function
    '<Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    'Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As System.IntPtr, ByVal length As Integer) As Integer
    'End Function
    '<Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    'Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Byte(), ByVal length As Integer) As Integer
    'End Function
    Public Function CreateSpectrumLinePeak(ByVal channel As Integer, ByVal width As Integer, ByVal height As Integer, ByVal color1 As System.Drawing.Color, ByVal color2 As System.Drawing.Color, ByVal color3 As System.Drawing.Color, ByVal background As System.Drawing.Color, ByVal linewidth As Integer, ByVal peakwidth As Integer, ByVal distance As Integer, ByVal peakdelay As Integer, ByVal linear As Boolean, ByVal fullSpectrum As Boolean, ByVal highQuality As Boolean) As System.Drawing.Bitmap
        Dim v_bitmap As System.Drawing.Bitmap : Dim v_graphics As System.Drawing.Graphics
        Dim v_pen As System.Drawing.Pen : Dim v_pen1 As System.Drawing.Pen
        Dim v_brush As System.Drawing.Brush
        If (((((channel <> 0) AndAlso (width > 1)) AndAlso (height > 1)) AndAlso (linewidth >= 1)) AndAlso (distance >= 0)) AndAlso (peakdelay >= 0) Then
            v_bitmap = Nothing : v_graphics = Nothing
            v_pen = Nothing : v_pen1 = Nothing
            Try
                Try
                    If a(channel, MaxFFT) > 0 Then
                        v_brush = New Drawing2D.LinearGradientBrush(New System.Drawing.Rectangle(0, 0, linewidth, height), color2, color1, Drawing2D.LinearGradientMode.Vertical)
                        Try
                            v_pen = New System.Drawing.Pen(v_brush, CSng(linewidth))
                            v_pen1 = New System.Drawing.Pen(color3, CSng(peakwidth))
                            v_bitmap = New System.Drawing.Bitmap(width, height)
                            v_graphics = System.Drawing.Graphics.FromImage(v_bitmap)
                            If highQuality Then
                                v_graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
                                v_graphics.CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
                                v_graphics.PixelOffsetMode = Not Drawing2D.PixelOffsetMode.Invalid
                                v_graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
                            Else
                                v_graphics.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed
                                v_graphics.CompositingQuality = Drawing2D.CompositingQuality.HighSpeed
                                v_graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.None
                                v_graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
                            End If
                            a(v_graphics, width, height, v_pen, v_pen1, linewidth, distance, peakdelay, background, _
                                linear, fullSpectrum)
                        Finally
                            If Not v_brush Is Nothing Then
                                v_brush.Dispose()
                            End If
                        End Try
                    End If
                Catch
                    v_bitmap = Nothing
                End Try
            Finally
                If Not v_pen Is Nothing Then
                    v_pen.Dispose()
                End If
                If Not v_pen1 Is Nothing Then
                    v_pen1.Dispose()
                End If
                If Not v_graphics Is Nothing Then
                    v_graphics.Dispose()
                End If
            End Try
            Return v_bitmap
        Else
            Return Nothing
        End If
        Return v_bitmap
    End Function
    Public Sub ClearPeaks()
        Dim v_i As Integer
        v_i = 0
        Do While v_i < _b.Length
            _b(v_i) = 0.0! : v_i += 1
        Loop
    End Sub
    Private Sub a(ByVal A_0 As System.Drawing.Graphics, ByVal A_1 As Integer, ByVal A_2 As Integer, ByVal A_3 As System.Drawing.Pen, ByVal A_4 As System.Drawing.Pen, ByVal A_5 As Integer, ByVal A_6 As Integer, ByVal A_7 As Integer, ByVal A_8 As System.Drawing.Color, ByVal A_9 As Boolean, ByVal A_10 As Boolean)
        Dim v_sng As Single : Dim v_sng1 As Single : Dim v_sng2 As Single
        Dim v_sng4 As Single : Dim v_i As Integer
        A_0.Clear(A_8) : k = A_9 : v_sng = 0.0! : v_sng1 = 0.0!
        v_sng2 = 0.0! : v_sng4 = 0.0!
        j = (CDbl(MaxFrequencySpectrum)) / (CDbl(A_1)) : v_i = MaxFrequencySpectrum + 1
        j = 1 : v_i = A_1 + 1
        If (Not A_10) AndAlso (v_i > (MaxFFTSampleIndex + 1)) Then
            v_i = MaxFFTSampleIndex + 1
        End If
        For v_i1 As Integer = 1 To v_i - 1
            If A_9 Then
                v_sng2 = (_a(v_i1) * (CSng(ScaleFactorLinear))) * (CSng(A_2))
                If v_sng4 <= v_sng2 Then
                    v_sng4 = v_sng2
                End If
                v_sng4 = 0.0!
            Else
                v_sng2 = (((CSng(System.Math.Sqrt(CDbl(_a(v_i1))))) * (CSng(ScaleFactorSqr))) * (CSng(A_2))) - 4.0!
                If v_sng4 <= v_sng2 Then
                    v_sng4 = v_sng2
                End If
                If (v_sng4 <= 0.0!) AndAlso (v_sng4 <= 0.0!) Then
                    v_sng4 = 0.0!
                End If
            End If
            If v_sng4 > (CSng(A_2)) Then
                v_sng4 = CSng(A_2)
            End If
            v_sng = (CSng(System.Math.Round((CDbl(v_i1)) / j))) - 1.0!
            If (((CInt(v_sng)) Mod (A_6 + A_5)) = 0) AndAlso (v_sng > v_sng1) Then
                v_sng4 = (v_sng4 + v_sng4) / 2.0!
                If _b(CInt(v_sng)) <= v_sng4 Then
                    _b(CInt(v_sng)) = v_sng4
                Else
                    _b(CInt(v_sng)) = (v_sng4 + ((CSng(A_7)) * _b(CInt(v_sng)))) / (CSng(A_7 + 1))
                End If
                A_0.DrawLine(A_3, (v_sng1 + (CSng(A_5 / 2))) + 1.0!, (CSng(A_2)) - 1.0!, (v_sng1 + (CSng(A_5 / 2))) + 1.0!, ((CSng(A_2)) - 1.0!) - v_sng4)
                A_0.DrawLine(A_4, v_sng1 + 1.0!, ((CSng(A_2)) - (A_4.Width / 2.0!)) - _b(CInt(v_sng)), ((v_sng1 + (CSng(A_5))) + (CSng(IIf(A_4.Width > 1.0!, 0, -1)))) + 1.0!, ((CSng(A_2)) - (A_4.Width / 2.0!)) - _b(CInt(v_sng)))
                v_sng1 = v_sng : v_sng4 = 0.0!
            End If
        Next v_i1
    End Sub
    Private Function a(ByVal A_0 As Integer, ByVal A_1 As Integer) As Integer
        If Not c Then
            Return BASS_ChannelGetData(A_0, _a, A_1)
        End If
    End Function
    Public Property ScaleFactorLinear() As Integer
        Get
            Return d
        End Get
        Set(ByVal Value As Integer)
            d = Value
        End Set
    End Property
    Public Property ScaleFactorSqr() As Integer
        Get
            Return e
        End Get
        Set(ByVal Value As Integer)
            e = Value
        End Set
    End Property
    Public ReadOnly Property MaxFFTSampleIndex() As Integer
        Get
            Return g
        End Get
    End Property
    Public Property MaxFFT() As BASSData
        Get
            Return h
        End Get
        Set(ByVal Value As BASSData)
            Select Case Value
                Case BASSData.BASS_DATA_FFT512
                    f = 1024 : h = Value : g = 255
                Case BASSData.BASS_DATA_FFT1024
                    f = 1024 : h = Value : g = 511
                Case BASSData.BASS_DATA_FFT2048
                    f = 2048 : h = Value : g = 1023
                Case Else
                    f = 4096 : h = BASSData.BASS_DATA_FFT4096 : g = 2047
                    If i > g Then
                        i = g
                    End If
                    Return
            End Select
        End Set
    End Property
    Public Property MaxFrequencySpectrum() As Integer
        Get
            Return i
        End Get
        Set(ByVal Value As Integer)
            If Value > MaxFFTSampleIndex Then
                i = MaxFFTSampleIndex
            End If
            If Value >= 1 Then
                i = Value
                Return
            End If
            i = 1
        End Set
    End Property
    Public Enum BASSData
        BASS_DATA_AVAILABLE = 0 : BASS_DATA_FFT_INDIVIDUAL = 16
        BASS_DATA_FFT_NOWINDOW = 32 : BASS_DATA_FLOAT = 1073741824
        BASS_DATA_FFT256 = -2147483648 : BASS_DATA_FFT512 = -2147483647
        BASS_DATA_FFT1024 = -2147483646 : BASS_DATA_FFT2048 = -2147483645
        BASS_DATA_FFT4096 = -2147483644 : BASS_DATA_FFT8192 = -2147483643
    End Enum
End Module

Example:
Code: [Select]
PictureBox1.Image = CreateSpectrumLinePeak(strm, PictureBox1.Width, PictureBox1.Height, Color.Aqua, Color.DeepSkyBlue, Color.White, Color.Black, 4, 2, 1, 22.5, False, False, True)


Full code BassPlayer sample project Click here
« Last Edit: 7 Feb '14 - 17:57 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #127 on: 8 Feb '14 - 21:38 »
Get New PlayList.dll for BassUn4Seen (debug) ;D Download : please wait!

Example: Using BassMod
Code: [Select]
« Last Edit: 8 Feb '14 - 21:52 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #128 on: 9 Feb '14 - 01:35 »
Get code Event Handle SongEnding, Create event by owner.:P

Code: [Select]
Private Event SongEnding As EventHandler
    Protected Overridable Sub SongEnded(ByVal handle As Integer)
        If BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES) = BASS_ChannelGetLength(strm, BASSMode.BASS_POS_BYTES) Then
            RaiseEvent SongEnding(Me, New System.EventArgs)
        End If
    End Sub

Example:
Code: [Select]
Imports System.Windows.Forms
Public Class Form1
    Inherits Form
    Private WithEvents openPlayBtn As Button
    Private fDlg As OpenFileDialog
    Private strm As Integer
    Private WithEvents timer1 As Timer
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Private Shared Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr, ByVal Guid As System.IntPtr) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _
   Private Shared Function BASS_StreamCreateFileMemory(<Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Boolean, ByVal A_1 As System.IntPtr, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Public Shared Function BASS_StreamFree(ByVal handle As Integer) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _
    Private Shared Function BASS_StreamCreateFileUnicode(<Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Boolean, <Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Public Shared Function BASS_ChannelPlay(ByVal handle As Integer, ByVal restart As Boolean) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Public Shared Function BASS_ChannelStop(ByVal handle As Integer) As Boolean
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Private Shared Function BASS_ChannelGetLength(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function
    <Runtime.InteropServices.DllImport("bass.dll", SetLastError:=False)> _
    Private Shared Function BASS_ChannelGetPosition(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function
    Public Function BASS_StreamCreateFile(ByVal [file] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
        On Error Resume Next
        flags = flags Or BASSFlag.BASS_UNICODE
        Return BASS_StreamCreateFileUnicode(False, [file], offset, length, flags)
    End Function
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle.ToInt32, IntPtr.Zero)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        openPlayBtn = New Button
        openPlayBtn.Text = "PlayOnOpen"
        openPlayBtn.Location = New Point(100, 100)
        timer1 = New Timer
        fDlg = New OpenFileDialog
        Me.Controls.Add(openPlayBtn)
        fDlg.FileName = Nothing
        fDlg.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3"
        AddHandler Me.SongEnding, AddressOf Me_SongEnding
    End Sub
    Private Event SongEnding As EventHandler
    Protected Overridable Sub SongEnded(ByVal handle As Integer)
        If BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES) = BASS_ChannelGetLength(strm, BASSMode.BASS_POS_BYTES) Then
            RaiseEvent SongEnding(Me, New System.EventArgs)
        End If
    End Sub
    Public Enum BASSInit
        BASS_DEVICE_DEFAULT = 0
    End Enum
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_UNICODE = -2147483648
        BASS_MUSIC_LOOP = 4
    End Enum
    Public Enum BASSMode
        BASS_POS_BYTES = 0
        BASS_POS_MUSIC_ORDERS = 1
        BASS_POS_MIDI_TICK = 2
        BASS_MUSIC_POSRESET = 32768
        BASS_MUSIC_POSRESETEX = 4194304
        BASS_MIXER_NORAMPIN = 8388608
        BASS_MIDI_DECAYSEEK = 16384
    End Enum
    Private Sub openPlayBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles openPlayBtn.Click
        Select Case openPlayBtn.Text
            Case "PlayOnOpen"
                If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_StreamFree(strm)
                    strm = BASS_StreamCreateFile(fDlg.FileName, 0, 0, BASSFlag.BASS_DEFAULT)
                    If strm Then BASS_ChannelPlay(strm, True)
                    openPlayBtn.Text = "Stop"
                    timer1.Start()
                End If
            Case Else
                BASS_ChannelStop(strm)
                openPlayBtn.Text = "PlayOnOpen"
        End Select
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
        SongEnded(strm)
    End Sub
    Private Sub Me_SongEnding(ByVal sender As Object, ByVal e As EventArgs)
        timer1.Stop()
        openPlayBtn.Text = "PlayOnOpen"
        MsgBox("Song Ended")
    End Sub
End Class
« Last Edit: 9 Feb '14 - 03:06 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #129 on: 10 Feb '14 - 03:58 »
Easy Created New PlayList (short code) ;D

Example:
Code: [Select]
Imports WMPLib
Public Class Form1
    Private ListBox1 As New System.Windows.Forms.ListBox
    Private pl As New WindowsMediaPlayer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenFileDialog1.Multiselect = True
        Me.Controls.Add(ListBox1)
        ListBox1.Hide()
    End Sub
    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
            For Each files As String In OpenFileDialog1.FileNames
                ListBox1.Items.Add(files)
                ListBox2.Items.Add(System.IO.Path.GetFileName(files))
            Next files
        End If
       End Sub
    Private Sub ListBox2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
        Dim ind As Integer = ListBox2.SelectedIndex()
        ListBox1.SetSelected(ind, True)
        If ListBox1.GetSelected(ind) = True Then
           pl.URL = ListBox1.SelectedItem.ToString
        End If
    End Sub
End Class
« Last Edit: 10 Feb '14 - 04:19 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #130 on: 11 Feb '14 - 03:17 »
Sample code NewPlayList DLL Class ;D

Code: [Select]
Public Class PlayList
    Inherits Object
    Public Shared NewPlayList As System.Windows.Forms.ListBox
    Shared Sub New()
        NewPlayList = New System.Windows.Forms.ListBox
    End Sub
    Public Shared Sub CreatedNewPlayList(ByVal hWnd As System.Windows.Forms.Form)
        On Error Resume Next
        hWnd.Controls.Add(NewPlayList)
        NewPlayList.Hide()
    End Sub
    Public Shared Sub AppendItems(ByVal Items As String())
        On Error Resume Next
        For Each files As String In Items
            NewPlayList.Items.Add(files)
        Next files
    End Sub
    Public Shared Function SelectedItem(ByVal CtlList As System.Windows.Forms.ListBox) As String
        On Error Resume Next     
        Dim ind As Integer = CtlList.SelectedIndex()
        Dim v_Items As String = Nothing
        NewPlayList.SetSelected(ind, True)
        If NewPlayList.GetSelected(ind) = True Then
            v_Items = NewPlayList.SelectedItem.ToString
        End If
        Return v_Items
    End Function
    Public Shared Sub SetSelectedIndex(ByVal CtlList As System.Windows.Forms.ListBox)
        On Error Resume Next
        If CtlList.SelectedIndex = -1 Then
            CtlList.SetSelected(0, True)
        End If
    End Sub
End Class

Example:
Code: [Select]
Imports WMPLib
Imports WindowsApplication1
Public Class Form1
    Private pl As New WindowsMediaPlayer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PlayList.CreatedNewPlayList(Me)
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog1.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        OpenFileDialog1.Multiselect = True
    End Sub
    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
            PlayList.AppendItems(OpenFileDialog1.FileNames)
            For Each files As String In OpenFileDialog1.FileNames
                ListBox1.Items.Add(System.IO.Path.GetFileName(files))
            Next files
            PlayList.SetSelectedIndex(ListBox1)
        End If
    End Sub
    Private Sub ListBox2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Button2.PerformClick()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        pl.URL = PlayList.SelectedItem(ListBox1)
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        pl.controls.stop()
    End Sub
End Class
« Last Edit: 11 Feb '14 - 05:45 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #131 on: 11 Feb '14 - 05:56 »
PlayList ConTextMenuStrip Added threads (Utilities) Class ;D

Code: [Select]
Public Class PlayListConTextMenuStrip
    Inherits Object
    Private Shared newListBox As System.Windows.Forms.ListBox
    Private Shared contextMenuStrip1 As System.Windows.Forms.ContextMenuStrip
    Private Shared toolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem
    Private Shared toolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem
    Shared Sub New()
        contextMenuStrip1 = New ContextMenuStrip
        contextMenuStrip1.RenderMode = ToolStripRenderMode.System
        toolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem("Clear Item Selected")
        toolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem("Clear Items All")
        contextMenuStrip1.Items.AddRange(New ToolStripMenuItem() {toolStripMenuItem1, toolStripMenuItem2})
        AddHandler toolStripMenuItem1.Click, New EventHandler(AddressOf toolStripMenuItem1_Click)
        AddHandler toolStripMenuItem2.Click, New EventHandler(AddressOf toolStripMenuItem2_Click)
    End Sub
    Public Shared Sub CreatedPlayListConTextMenu(ByVal ctlList As System.Windows.Forms.ListBox)
        On Error Resume Next
        newListBox = ctlList
        ctlList.ContextMenuStrip = contextMenuStrip1
    End Sub
    Private Shared Sub toolStripMenuItem1_Click(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next
        newListBox.Items.RemoveAt(newListBox.SelectedIndex)
    End Sub
    Private Shared Sub toolStripMenuItem2_Click(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next
        newListBox.Items.Clear()
    End Sub
End Class

Example:
Code: [Select]
Imports WMPLib
Imports NewPlayList
Imports WindowsApplication1
Public Class Form1
    Private pl As New WindowsMediaPlayer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PlayList.CreatedNewPlayList(Me)
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog1.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        OpenFileDialog1.Multiselect = True
        PlayListConTextMenuStrip.CreatedPlayListConTextMenu(ListBox1)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PlayList.AppendItems(OpenFileDialog1.FileNames)
            For Each files As String In OpenFileDialog1.FileNames
                ListBox1.Items.Add(System.IO.Path.GetFileName(files))
            Next files
            PlayList.SetSelectedIndex(ListBox1)
        End If
    End Sub
    Private Sub ListBox2_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Button2.PerformClick()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        pl.URL = PlayList.SelectedItem(ListBox1)
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        pl.controls.stop()
    End Sub
End Class
« Last Edit: 11 Feb '14 - 07:29 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #132 on: 11 Feb '14 - 09:13 »
Sample code: ListView Player ;D Using: DoubleClick item list to playing.

Code: [Select]
Imports System.Windows.Forms
Imports System
Imports System.Drawing
Imports WMPLib
Public Class Form1
    Inherits Form
    Private lblStatus As New Label
    Private Ofd As New OpenFileDialog
    Private WithEvents Lv As New ListView
    Private WithEvents Timer1 As New Timer
    Private WithEvents wmp As New WindowsMediaPlayer
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        InitializeComponent()
        lblStatus.Text = "Status"
        lblStatus.AutoSize = True
        lblStatus.Location = New Point()
        Ofd.FileName = Nothing
        Ofd.Filter = "Audio Files(*.mp3)|*.mp3"
        Ofd.Multiselect = True
        PlayListViewCreated(Me, Lv, 0, 0, 300, 200, "Song name", 240, "Duration", 60)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            PlayListViewAppendItems(Lv, Ofd)
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Lv.SelectedIndices.Count > 0 Then
            wmp.URL = Lv.Items(Lv.SelectedIndices(0)).Text
            TrackBar1.Maximum = wmp.newMedia(Lv.Items(Lv.SelectedIndices(0)).Text).duration
            Lv.Select()
            TrackBar1.TickFrequency = CInt(TrackBar1.Maximum / 100 * 10)
            Timer1.Enabled = True
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        wmp.controls.stop()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = wmp.controls.currentPositionString
        TrackBar1.Value = CInt(wmp.controls.currentPosition)
        If wmp.playState = WMPPlayState.wmppsStopped Then
            Label1.Text = "00:00"
            If TrackBar1.Value = TrackBar1.Minimum Then
                Timer1.Enabled = False
            End If
        End If
        Label2.Text = StatusString()
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        wmp.controls.currentPosition = CDbl(TrackBar1.Value)
    End Sub
    Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Lv.DoubleClick
        Button2.PerformClick()
    End Sub
    Private Function StatusString() As String
        Dim v_retString As String = Nothing
        Select Case wmp.playState
            Case WMPPlayState.wmppsBuffering
                v_retString = "Buffering"
            Case WMPPlayState.wmppsLast
                v_retString = "Last"
            Case WMPPlayState.wmppsMediaEnded
                v_retString = "MediaEnded"
            Case WMPPlayState.wmppsPaused
                v_retString = "Paused"
            Case WMPPlayState.wmppsPlaying
                v_retString = "Playing"
            Case WMPPlayState.wmppsReady
                v_retString = "Ready"
            Case WMPPlayState.wmppsReconnecting
                v_retString = "Reconnecting"
            Case WMPPlayState.wmppsScanForward
                v_retString = "ScanForward"
            Case WMPPlayState.wmppsScanReverse
                v_retString = "ScanReverse"
            Case WMPPlayState.wmppsStopped
                v_retString = "Stopped"
            Case WMPPlayState.wmppsTransitioning
                v_retString = "Transitioning"
            Case WMPPlayState.wmppsUndefined
                v_retString = "Undefined"
            Case WMPPlayState.wmppsWaiting
                v_retString = "Waiting"
            Case Else
                Exit Select
        End Select
        Return v_retString
    End Function
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        wmp.close()
    End Sub
    Private Sub PlayListViewCreated(ByVal hWnd As Form, ByVal CtlLV As ListView, ByVal Left As Integer, ByVal Rigth As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal ColumnText As String, ByVal ColumnWidth As Integer, ByVal SubColumnText As String, ByVal SubColumnWidth As Integer)
        CtlLV.GridLines = True
        CtlLV.View = View.Details
        CtlLV.SetBounds(Left, Top, Width, Height)
        CtlLV.Columns.Add(ColumnText, ColumnWidth, HorizontalAlignment.Left)
        CtlLV.Columns.Add(SubColumnText, SubColumnWidth, HorizontalAlignment.Left)
        hWnd.Controls.Add(CtlLV)
    End Sub
    Public Sub PlayListViewAppendItems(ByVal CtlLV As ListView, ByVal fDlg As OpenFileDialog)
        Dim ind As Integer = CtlLV.Items.Count
        For Each files As String In fDlg.FileNames
            CtlLV.Items.Add(files).SubItems.Add(wmp.newMedia(files).durationString)
        Next files
        CtlLV.Items(0).Selected = True
        CtlLV.Select()
    End Sub
End Class
« Last Edit: 12 Feb '14 - 00:40 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #133 on: 13 Feb '14 - 06:31 »
New! Alvas.Audio.dll UnRegister and Using DLLs ;D Download: please wait..
It easy for creatting sound record and player program. ::)
----------------------------------------------------------------
Get sound mod for sound player
Code: [Select]
« Last Edit: 13 Feb '14 - 06:39 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #134 on: 13 Feb '14 - 06:37 »
Get BassPlayList.Dll ;D Click here

Threads:
1. Browse files to the list.
2. Drag drop files to the list.
3. Using ContextMenu, RightClick to clear item selected or clear items all.  

Example:
Code: [Select]
Imports Un4seen.Bass 'Reference bass.net.dll
Imports BassPlayList 'Reference BassPlayList.dll
Public Class Player
    Private fDlg As New OpenFileDialog
    Private WithEvents timePosition As New Timer
    Private Event SongEnding As EventHandler
    Private Event SongStopping As EventHandler
    Private strm As Integer
    Private Sub Player_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            PlayList.BASS_PlayListRegBassNet() 'Out of splash.
            Un4seen.Bass.Bass.BASS_Init(-1, 44100, Un4seen.Bass.BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
        Catch ex As Exception
            MsgBox(Un4seen.Bass.Bass.BASS_ErrorGetCode)
        End Try
    End Sub
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        InitializeComponent()
        PlayList.BASS_PlayListCreated(Me, ListBox1) 'Create new list.
        ListBox1.HorizontalScrollbar = True
        fDlg.FileName = Nothing
        fDlg.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        fDlg.Multiselect = True
        timePosition.Interval = 35
        CheckBox1.Checked = True
        ProgressBar1.Maximum = 32768
        ProgressBar2.Maximum = 32768
        AddHandler Me.SongEnding, New EventHandler(AddressOf Me_SongEnding)
        AddHandler Me.SongStopping, New EventHandler(AddressOf Me_SongStopping)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next
        If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            PlayList.BASS_PlayListAppendItems(fDlg.FileNames, ListBox1) 'Added items to lists.
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        On Error Resume Next
        Un4seen.Bass.Bass.BASS_StreamFree(strm)
        strm = Un4seen.Bass.Bass.BASS_StreamCreateFile(PlayList.BASS_PlayListSelectedItem(ListBox1), 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT)
        If strm Then
            Un4seen.Bass.Bass.BASS_ChannelPlay(strm, True)
            Label1.Text = Un4seen.Bass.Utils.FixTimespan(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetLength(strm)), "mm:ss")
            TrackBar1.Maximum = CInt(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetLength(strm)))
            TrackBar1.TickFrequency = CInt(TrackBar1.Maximum / 100 * 10)
            timePosition.Enabled = True
        End If
        Button3.Text = "Pause"
    End Sub
    Private Sub timePosition_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timePosition.Tick
        On Error Resume Next
        TrackBar1.Value = CInt(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetPosition(strm)))
        Label3.Text = Un4seen.Bass.Utils.FixTimespan(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetPosition(strm)), "mm:ss")
        ProgressBar1.Value = BASS_LevelMeter("L")
        ProgressBar2.Value = BASS_LevelMeter("H")
        If CheckBox1.CheckState = CheckState.Checked Then
            BASS_InvokeSongEnded()
        Else
            BASS_InvokeSongStopped()
        End If
        Label2.Text = BASS_Status()
    End Sub
    Private Sub Me_SongEnding(ByVal sender As Object, ByVal e As EventArgs)
        timePosition.Enabled = False
        Dim ind As Integer = ListBox1.SelectedIndex
        Try
            ListBox1.SetSelected(ind + 1, True)
            Button2.PerformClick()
        Catch ex As Exception
            ListBox1.SetSelected(0, True)
            Button2.PerformClick()
        End Try
    End Sub
    Private Sub Me_SongStopping(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next
        TrackBar1.Value = TrackBar1.Minimum
        Label2.Text = "stopped"
        Label3.Text = "00:00"
        ProgressBar1.Value = ProgressBar1.Minimum
        ProgressBar2.Value = ProgressBar2.Minimum
        Button3.Text = "Pause"
        timePosition.Enabled = False
    End Sub
    Private Function BASS_LevelMeter(ByVal filter As String) As Integer
        On Error Resume Next
        Dim lev As Integer = Un4seen.Bass.Bass.BASS_ChannelGetLevel(strm)
        Select Case filter
            Case "L"
                Return Un4seen.Bass.Utils.LowWord32(lev)
            Case "H"
                Return Un4seen.Bass.Utils.HighWord32(lev)
            Case Else
                Exit Select
        End Select
    End Function
    Private Sub BASS_InvokeSongEnded()
        On Error Resume Next
        If Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetPosition(strm)) >= Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(strm, Un4seen.Bass.Bass.BASS_ChannelGetLength(strm)) Then
            RaiseEvent SongEnding(Me, New EventArgs)
        End If
    End Sub
    Private Sub BASS_InvokeSongStopped()
        On Error Resume Next
        If Un4seen.Bass.Bass.BASS_ChannelIsActive(strm) = Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED Then
            RaiseEvent SongStopping(Me, New EventArgs)
        End If
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Un4seen.Bass.Bass.BASS_ChannelSetPosition(strm, Un4seen.Bass.Bass.BASS_ChannelSeconds2Bytes(strm, CDbl(TrackBar1.Value)))
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        On Error Resume Next
        Un4seen.Bass.Bass.BASS_ChannelStop(strm)
        BASS_InvokeSongStopped()
    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        On Error Resume Next
        Button2.PerformClick()
    End Sub
    Private ReadOnly Property BASS_Status() As String
        Get
            On Error Resume Next
            Dim v_state As String = Nothing
            Select Case Un4seen.Bass.Bass.BASS_ChannelIsActive(strm)
                Case Un4seen.Bass.BASSActive.BASS_ACTIVE_PAUSED
                    v_state = "paused"
                Case Un4seen.Bass.BASSActive.BASS_ACTIVE_PLAYING
                    v_state = "playing"
                Case Un4seen.Bass.BASSActive.BASS_ACTIVE_STALLED
                    v_state = "stalled"
                Case Un4seen.Bass.BASSActive.BASS_ACTIVE_STOPPED
                    v_state = "stopped"
                Case Else
                    Exit Select
            End Select
            Return v_state
        End Get
    End Property
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If BASS_Status = "stopped" Then Return
        On Error Resume Next
        Select Case Button3.Text
            Case "Pause"
                Un4seen.Bass.Bass.BASS_ChannelPause(strm)
                Button3.Text = "Resume"
            Case Else
                Un4seen.Bass.Bass.BASS_ChannelPlay(strm, False)
                Button3.Text = "Pause"
        End Select
    End Sub
End Class
« Last Edit: 18 Feb '14 - 01:58 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #135 on: 18 Feb '14 - 12:07 »
Get code PlayList DirectXPlayBack DLL Class ;D

Code: [Select]
Imports System
Imports System.Drawing
Imports Microsoft.DirectX
Imports System.Windows.Forms
Imports Microsoft.DirectX.AudioVideoPlayback
Public Class DirectXPlayList
    Inherits Object
    Private Shared newList As ListBox
    Private Shared cList As ListBox
    Private Shared cBtn As Button
    Private Shared WithEvents pl As Audio
    Public Shared timePosition As Timer
    Public Shared Event SongStopping As EventHandler
    Shared Sub New()
        newList = New ListBox
        cList = New ListBox
        cBtn = New Button
        timePosition = New Timer
    End Sub
    Private Shared Sub pl_Stopping(ByVal sender As Object, ByVal e As EventArgs) Handles pl.Stopping
        timePosition.Enabled = False
        RaiseEvent SongStopping(sender, New EventArgs)
    End Sub
    Private Shared Sub pl_Ending(ByVal sender As Object, ByVal e As EventArgs) Handles pl.Ending
        Dim ind As Integer = cList.SelectedIndex
        Try
            cList.SetSelected(ind + 1, True)
            PlayNoneStop(cBtn)
        Catch ex As Exception
            cList.SetSelected(0, True)
            PlayNoneStop(cBtn)
        End Try
    End Sub
    Public Shared Sub PlayNoneStop(ByVal ctlBtnPlay As Button)
        cBtn = ctlBtnPlay
        ctlBtnPlay.PerformClick()
    End Sub
    Public Shared Sub Created(ByVal handle As Form, ByVal ctllist As ListBox)
        On Error Resume Next
        cList = ctllist
        ctllist.HorizontalScrollbar = True
        newList.Size = ctllist.Size
        newList.Location = ctllist.Location
        handle.Controls.Add(newList)
    End Sub
    Public Shared Sub AppendItems(ByVal filenames As String(), ByVal ctlList As ListBox)
        On Error Resume Next
        For Each files As String In filenames
            newList.Items.Add(files)
            ctlList.Items.Add(IO.Path.GetFileName(files))
        Next
        If ctlList.SelectedIndex = -1 Then
            ctlList.SetSelected(0, True)
        End If
    End Sub
    Public Shared ReadOnly Property SelectedItem(ByVal ctlList As ListBox) As String
        Get
            On Error Resume Next
            Dim ind As Integer = ctlList.SelectedIndex
            newList.SetSelected(ind, True)
            Return newList.SelectedItem
        End Get
    End Property
    Public Shared Sub OpenSound(ByVal filename As String)
        On Error Resume Next
        pl.StopWhenReady()
        pl = Audio.FromFile(filename)
    End Sub
    Public Shared Sub PlaySound()
        On Error Resume Next
        pl.Play()
    End Sub
    Public Shared Sub PauseSound()
        On Error Resume Next
        pl.Pause()
    End Sub
    Public Shared Sub ResumeSound()
        On Error Resume Next
        pl.Play()
    End Sub
    Public Shared Sub StopSound()
        On Error Resume Next
        pl.StopWhenReady()
    End Sub
    Public Shared ReadOnly Property DurationString() As String
        Get
            On Error Resume Next
            Dim span As TimeSpan
            span = TimeSpan.FromSeconds(pl.Duration)
            Return Strings.Right(Strings.Left(span.ToString, 8), 5)
        End Get
    End Property
    Public Shared ReadOnly Property PositionString() As String
        Get
            On Error Resume Next
            Dim span As TimeSpan
            span = TimeSpan.FromSeconds(pl.CurrentPosition)
            Return Strings.Right(Strings.Left(span.ToString, 8), 5)
        End Get
    End Property
    Public Shared ReadOnly Property CurrentPosition() As Double
        Get
            On Error Resume Next
            Return pl.CurrentPosition()
        End Get
    End Property
    Public Shared ReadOnly Property MaxPosition() As Double
        Get
            On Error Resume Next
            Return pl.Duration()
        End Get
    End Property
    Public Shared Sub ChangePosition(ByVal ms As Double)
        On Error Resume Next
        pl.CurrentPosition = ms
    End Sub
    Public Shared ReadOnly Property StatusString() As String
        Get
            On Error Resume Next
            Dim v_state As String = Nothing
            Select Case pl.State
                Case StateFlags.Paused
                    v_state = "paused"
                Case StateFlags.Running
                    v_state = "playing"
                Case StateFlags.Stopped
                    v_state = "stopped"
                Case Else
                    v_state = Nothing
            End Select
            Return v_state
        End Get
    End Property
End Class

Example:
Code: [Select]
Public Class Form1
    Private fDlg As New OpenFileDialog
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DirectXPlayList.Created(Me, ListBox1)
    End Sub
    Public Sub New()
        MyBase.New()
        Me.CenterToScreen()
        InitializeComponent()
        fDlg.FileName = Nothing
        fDlg.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        fDlg.Multiselect = True
        DirectXPlayList.PlayNoneStop(Button2)
        AddHandler DirectXPlayList.timePosition.Tick, AddressOf timePosition_Tick
        AddHandler DirectXPlayList.SongStopping, AddressOf DirectXPlayList_SongStopping
    End Sub
    Private Sub DirectXPlayList_SongStopping(ByVal sender As Object, ByVal e As EventArgs)
        TrackBar1.Value = TrackBar1.Minimum
        Label2.Text = "stopped"
        Label3.Text = "00:00"
        Button3.Text = "Pause"
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            DirectXPlayList.AppendItems(fDlg.FileNames, ListBox1)
        End If
    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Button2.PerformClick()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ListBox1.SelectedIndex = -1 Then Return
        DirectXPlayList.OpenSound(DirectXPlayList.SelectedItem(ListBox1))
        Label1.Text = DirectXPlayList.DurationString()
        TrackBar1.Maximum = DirectXPlayList.MaxPosition()
        TrackBar1.TickFrequency = TrackBar1.Maximum / 100 * 10
        DirectXPlayList.PlaySound()
        Button3.Text = "Pause"
        DirectXPlayList.timePosition.Enabled = True
    End Sub
    Private Sub timePosition_Tick(ByVal sender As Object, ByVal e As EventArgs)
        TrackBar1.Value = DirectXPlayList.CurrentPosition()
        Label2.Text = DirectXPlayList.StatusString()
        Label3.Text = DirectXPlayList.PositionString()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If ListBox1.SelectedIndex = -1 Then Return
        DirectXPlayList.StopSound()
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        DirectXPlayList.ChangePosition(CDbl(TrackBar1.Value))
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If DirectXPlayList.StatusString = "stopped" Or DirectXPlayList.StatusString = Nothing Then Return
        Select Case Button3.Text
            Case "Pause"
                DirectXPlayList.PauseSound()
                Button3.Text = "Resume"
            Case Else
                DirectXPlayList.ResumeSound()
                Button3.Text = "Pause"
        End Select
    End Sub
End Class



« Last Edit: 18 Feb '14 - 12:19 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #136 on: 20 Feb '14 - 03:38 »
Get code: Created SoundPlayer Program, Using.. DirectX.DirectSound DLL ;D
              Get LevelMeter for SoundPlayer ;D

Example:
Code: [Select]
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectSound
Imports User.DirectX.DirectSound.VolumeMeter
Public Class Form1
    Private SoundDevicesCollection As Microsoft.DirectX.DirectSound.DevicesCollection
    Private SoundDevice As Microsoft.DirectX.DirectSound.Device
    Private SoundSecondaryBuffer As Microsoft.DirectX.DirectSound.SecondaryBuffer
    Private Priority As Integer
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        InitializeComponent()
        VolumeMeter1.SelectedDeviceIndex = 0
        VolumeMeter1.DeviceNames.Add("Primary Sound Capture Driver")
        VolumeMeter1.FrameDelay = 10
        VolumeMeter1.SampleDelay = 50
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog1.Filter = "Audio Files(*.wav)|*.wav"
    End Sub
    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
            TextBox1.Clear()
            TextBox1.Text = OpenFileDialog1.SafeFileName
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        StopSound()
        OpenSound(TextBox1.Text)
        PlaySound()
        VolumeMeter1.VisualizerOn = True
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        StopSound()
        VolumeMeter1.VisualizerOn = False
    End Sub
    '---------------------------------------------------------------------------
    Public Sub OpenSound(ByVal FileName As String)
        On Error Resume Next
        OpenSound(FileName, Me, SoundDevicesCollection, SoundDevice)
    End Sub
    Public Sub PlaySound()
        On Error Resume Next
        SoundSecondaryBuffer.Play(Priority, BufferPlayFlags.Default)
    End Sub
    Public Sub StopSound()
        On Error Resume Next
        SoundSecondaryBuffer.Stop()
    End Sub
    Protected Sub OpenSound(ByVal FileName As String, ByVal hForm As Form, ByVal SoundDevicesCollection As Microsoft.DirectX.DirectSound.DevicesCollection, ByVal SoundDevice As Microsoft.DirectX.DirectSound.Device)
        SoundDevicesCollection = New Microsoft.DirectX.DirectSound.DevicesCollection
        SoundDevice = New Device(SoundDevicesCollection(0).DriverGuid)
        SoundDevice.SetCooperativeLevel(hForm.Handle, CooperativeLevel.Normal)
        SoundSecondaryBuffer = New SecondaryBuffer(FileName, SoundDevice)
    End Sub
End Class


« Last Edit: 20 Feb '14 - 07:34 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #137 on: 20 Feb '14 - 07:58 »
Get code LED Level Meter Decompiler ;D

Open vb.net studio and select creatting Library class and save project

Add image bitmap to the Resource folder, for Toolbox picture

Creatting field operator variable

'----------------------------------------------------------------------
<System.ComponentModel.Designer(GetType(LEDLevelMeterDesigner))> _
<ToolboxBitmap(GetType(LEDLevelMeter), "KA.Audio.VuMeter.bmp")> _
Public Class LEDLevelMeter
    Inherits System.Windows.Forms.UserControl
#Region "LEDLevelMeter Fields"
    Private CurrentLevel As Integer
    Private PeakLevel As Integer
    Private LedCount1 As Integer
    Private LedCount2 As Integer
    Private LedCount3 As Integer
    Private calcValue As Integer
    Private calcPeak As Integer
    Private LedColorOn1 As System.Drawing.Color
    Private LedColorOn2 As System.Drawing.Color
    Private LedColorOn3 As System.Drawing.Color
    Private LedColorOff1 As System.Drawing.Color
    Private LedColorOff2 As System.Drawing.Color
    Private LedColorOff3 As System.Drawing.Color
    Private BorderColor As System.Drawing.Color
    Private Min As Integer
    Private Max As Integer
    Private PeakHoldTime As Integer
    Private ShowPeak As Boolean
    Private Vertical As Boolean
    Private DegLow As Double
    Private DegHigh As Double
    Protected timer1 As System.Windows.Forms.Timer
    Private Led As System.Drawing.Size
    Private LedSpacing As Integer
    Private FormType As MeterScale
#End Region
'----------------------------------------------------------------------------
« Last Edit: 20 Feb '14 - 15:14 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #138 on: 20 Feb '14 - 15:16 »
Creatting Constructors

'------------------------------------------------------------
#Region "LEDLevelMeter Constructors"
    Public Sub New()
        MyBase.New()
        Me.LedCount1 = 8
        Me.LedCount2 = 6
        Me.LedCount3 = 4
        Me.LedColorOn1 = System.Drawing.Color.LimeGreen
        Me.LedColorOn2 = System.Drawing.Color.Yellow
        Me.LedColorOn3 = System.Drawing.Color.Red
        Me.LedColorOff1 = System.Drawing.Color.DarkGreen
        Me.LedColorOff2 = System.Drawing.Color.Olive
        Me.LedColorOff3 = System.Drawing.Color.Maroon
        Me.BorderColor = System.Drawing.Color.DimGray
        Me.Min = 0
        Me.Max = 32768
        Me.PeakHoldTime = 1000
        Me.ShowPeak = True
        Me.Vertical = False
        Me.DegLow = 2.5132741228718345
        Me.DegHigh = 3.7699111843077517
        Me.Led = New System.Drawing.Size(6, 14)
        Me.LedSpacing = 3
        Me.FormType = MeterScale.Log10
        MyBase.Name = "LEDLevelMeter"
        CalcSize()
        MyBase.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, True)
        MyBase.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, True)
        MyBase.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, True)
        Me.timer1 = New System.Windows.Forms.Timer
        Me.timer1.Interval = Me.PeakHoldTime
        Me.timer1.Enabled = False
        AddHandler Me.timer1.Tick, New System.EventHandler(AddressOf Me.timer1_Tick)
    End Sub
#End Region
'----------------------------------------------------------------------------------

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #139 on: 20 Feb '14 - 15:23 »
User control form design

'-------------------------------------------------
#Region "Windows Form Designer generated code"
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'LEDLevelMeter
        '
        Me.Name = "LEDLevelMeter"
        Me.ResumeLayout(False)

    End Sub
#End Region
'------------------------------------------------

Creatting methods

'----------------------------------------------------------------------------
#Region "LEDLevelMeter Methods"
    Protected Overloads Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim v_graphics As System.Drawing.Graphics
        v_graphics = e.Graphics
        DrawBorder(v_graphics)
        DrawLeds(v_graphics)
    End Sub
    Protected Overloads Overrides Sub OnResize(ByVal e As System.EventArgs)
        CalcSize()
        MyBase.OnResize(e)
        MyBase.Invalidate()
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
        Me.timer1.[Stop]()
        Me.PeakLevel = Me.CurrentLevel
        MyBase.Invalidate()
        Me.timer1.Start()
    End Sub
    Private Sub CalcSize()
        Dim v_bl As Boolean
        v_bl = Not Me.Vertical
        If Not v_bl Then
            MyBase.Size = New System.Drawing.Size(Me.Led.Width + (Me.LedSpacing * 2), (((Me.LedCount1 + Me.LedCount2) + Me.LedCount3) * (Me.Led.Height + Me.LedSpacing)) + Me.LedSpacing)
        Else
            MyBase.Size = New System.Drawing.Size((((Me.LedCount1 + Me.LedCount2) + Me.LedCount3) * (Me.Led.Width + Me.LedSpacing)) + Me.LedSpacing, Me.Led.Height + (Me.LedSpacing * 2))
        End If
    End Sub
    Private Sub DrawLeds(ByVal g As System.Drawing.Graphics)
        Dim v_i As Integer
        Dim v_rectangle As System.Drawing.Rectangle
        Dim v_bl As Boolean
        Dim v_rectangle1 As System.Drawing.Rectangle
        v_bl = Me.FormType <> MeterScale.Log10
        If Not v_bl Then
            Me.calcValue = CInt(System.Math.Log10(((CDbl(Me.CurrentLevel)) / (CDbl(Me.Max / 10))) + 1) * (CDbl((Me.LedCount1 + Me.LedCount2) + Me.LedCount3)))
            v_bl = Not Me.ShowPeak
            If Not v_bl Then
                Me.calcPeak = CInt(System.Math.Log10(((CDbl(Me.PeakLevel)) / (CDbl(Me.Max / 10))) + 1) * (CDbl((Me.LedCount1 + Me.LedCount2) + Me.LedCount3)))
            End If
        End If
        v_bl = Me.FormType <> MeterScale.Analog
        If Not v_bl Then
            Me.calcValue = CInt((((CDbl(Me.CurrentLevel)) / (CDbl(Me.Max))) * (CDbl((Me.LedCount1 + Me.LedCount2) + Me.LedCount3))) + 0.5)
            v_bl = Not Me.ShowPeak
            If Not v_bl Then
                Me.calcPeak = CInt((((CDbl(Me.PeakLevel)) / (CDbl(Me.Max))) * (CDbl((Me.LedCount1 + Me.LedCount2) + Me.LedCount3))) + 0.5)
            End If
        End If
        v_i = 0
        Do While (v_i < ((Me.LedCount1 + Me.LedCount2) + Me.LedCount3))
            v_bl = Not Me.Vertical
            If Not v_bl Then
                v_rectangle1 = MyBase.ClientRectangle
                v_rectangle1 = MyBase.ClientRectangle
                v_rectangle = New System.Drawing.Rectangle(v_rectangle1.X + Me.LedSpacing, v_rectangle1.Height - ((v_i + 1) * (Me.Led.Height + Me.LedSpacing)), Me.Led.Width, Me.Led.Height)
                v_bl = Not ((v_i < Me.calcValue) Or (((v_i + 1) = Me.calcPeak) And Me.ShowPeak))
                If Not v_bl Then
                    v_bl = v_i >= Me.LedCount1
                    If Not v_bl Then
                        g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn1), v_rectangle)
                    Else
                        v_bl = v_i >= (Me.LedCount1 + Me.LedCount2)
                        If Not v_bl Then
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn2), v_rectangle)
                            GoTo ILO_0229
                        End If
                        g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn3), v_rectangle)
                    End If
ILO_0229:
                Else
                    v_bl = v_i >= Me.LedCount1
                    If Not v_bl Then
                        g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff1), v_rectangle)
                    Else
                        v_bl = v_i >= (Me.LedCount1 + Me.LedCount2)
                        If Not v_bl Then
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff2), v_rectangle)
                        Else
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff3), v_rectangle)
                        End If
                    End If
                End If
            Else
                v_rectangle1 = MyBase.ClientRectangle
                v_rectangle1 = MyBase.ClientRectangle
                v_rectangle = New System.Drawing.Rectangle((v_rectangle1.X + (v_i * (Me.Led.Width + Me.LedSpacing))) + Me.LedSpacing, v_rectangle1.Y + Me.LedSpacing, Me.Led.Width, Me.Led.Height)
                v_bl = Not ((v_i < Me.calcValue) Or (((v_i + 1) = Me.calcPeak) And Me.ShowPeak))
                If Not v_bl Then
                    v_bl = v_i >= Me.LedCount1
                    If Not v_bl Then
                        g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn1), v_rectangle)
                    Else
                        v_bl = v_i >= (Me.LedCount1 + Me.LedCount2)
                        If Not v_bl Then
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn2), v_rectangle)
                        Else
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOn3), v_rectangle)
                        End If
                    End If
                Else
                    v_bl = v_i >= Me.LedCount1
                    If Not v_bl Then
                        g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff1), v_rectangle)
                    Else
                        v_bl = v_i >= (Me.LedCount1 + Me.LedCount2)
                        If Not v_bl Then
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff2), v_rectangle)
                        Else
                            g.FillRectangle(New System.Drawing.SolidBrush(Me.LedColorOff3), v_rectangle)
                        End If
                    End If
                End If
            End If
            v_i += 1
        Loop
    End Sub
    Private Sub DrawBorder(ByVal g As System.Drawing.Graphics)
        Dim v_rectangle1 As System.Drawing.Rectangle = MyBase.ClientRectangle
        v_rectangle1 = MyBase.ClientRectangle
        g.FillRectangle(New System.Drawing.SolidBrush(MyBase.BackColor), New System.Drawing.Rectangle(v_rectangle1.X, v_rectangle1.Y, v_rectangle1.Width, v_rectangle1.Height))
    End Sub
#End Region
'-----------------------------------------------------------------------------


sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #140 on: 20 Feb '14 - 15:25 »
Creatting properties

'----------------------------------------------------------------------
#Region "VuMeter Properties"
    <System.ComponentModel.Description("Display value in analog or logarithmic scale"), System.ComponentModel.Category("LEDLevelMeter")> _
        Public Property MeterScale() As MeterScale
        Get
            Return Me.FormType
        End Get
        Set(ByVal Value As MeterScale)
            Me.FormType = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter"), System.ComponentModel.Description("Led size (1 to 72 pixels)")> _
    Public Property LedSize() As System.Drawing.Size
        Get
            Return Me.Led
        End Get
        Set(ByVal Value As System.Drawing.Size)
            Dim v_bl As Boolean
            v_bl = Value.Height >= 1
            If Not v_bl Then
                Me.Led.Height = 1
            Else
                v_bl = Value.Height <= 72
                If Not v_bl Then
                    Me.Led.Height = 72
                Else
                    Me.Led.Height = Value.Height
                End If
            End If
            v_bl = Value.Width >= 1
            If Not v_bl Then
                Me.Led.Width = 1
            Else
                v_bl = Value.Width <= 72
                If Not v_bl Then
                    Me.Led.Width = 72
                Else
                    Me.Led.Width = Value.Width
                End If
            End If
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter"), System.ComponentModel.Description("Led spacing (0 to 72 pixels)")> _
    Public Property LedSpace() As Integer
        Get
            Return Me.LedSpacing
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= 0
            If Not v_bl Then
                Me.LedSpacing = 0
            Else
                v_bl = Value <= 72
                If Not v_bl Then
                    Me.LedSpacing = 72
                Else
                    Me.LedSpacing = Value
                End If
            End If
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Led bar is vertical"), System.ComponentModel.Category("LEDLevelMeter")> _
    Public Property VerticalBar() As Boolean
        Get
            Return Me.Vertical
        End Get
        Set(ByVal Value As Boolean)
            Me.Vertical = Value
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Max value from total LedCount to 65535"), System.ComponentModel.Category("LEDLevelMeter")> _
    Public Property LevelMax() As Integer
        Get
            Return Me.Max
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= ((Led1Count + Led2Count) + Led3Count)
            If Not v_bl Then
                Me.Max = (Led1Count + Led2Count) + Led3Count
            Else
                v_bl = Value <= 32768
                If Not v_bl Then
                    Me.Max = 32768
                Else
                    Me.Max = Value
                End If
            End If
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter"), System.ComponentModel.Description("The level shown (between Min and Max)")> _
    Public Property Level() As Integer
        Get
            Return Me.CurrentLevel
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value = Me.CurrentLevel
            If v_bl Then
                Return
            End If
            v_bl = Value >= Me.Min
            If Not v_bl Then
                Me.CurrentLevel = Me.Min
            Else
                v_bl = Value <= Me.Max
                If Not v_bl Then
                    Me.CurrentLevel = Me.Max
                Else
                    Me.CurrentLevel = Value
                End If
            End If
            v_bl = Not ((Me.CurrentLevel > Me.PeakLevel) And Me.ShowPeak)
            If Not v_bl Then
                Me.PeakLevel = Me.CurrentLevel
                Me.timer1.[Stop]()
                Me.timer1.Start()
            End If
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("How many mS to hold peak indicator (50 to 10000mS)"), System.ComponentModel.Category("LEDLevelMeter")> _
    Public Property Peakms() As Integer
        Get
            Return Me.PeakHoldTime
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= 50
            If Not v_bl Then
                Me.PeakHoldTime = 50
            Else
                v_bl = Value <= 10000
                If Not v_bl Then
                    Me.PeakHoldTime = 10000
                Else
                    Me.PeakHoldTime = Value
                End If
            End If
            Me.timer1.Interval = Me.PeakHoldTime
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter"), System.ComponentModel.Description("Use peak indicator")> _
    Public Property PeakHold() As Boolean
        Get
            Return Me.ShowPeak
        End Get
        Set(ByVal Value As Boolean)
            Me.ShowPeak = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Number of Leds in first area (0 to 32, default 6) Total Led count must be at leas" & "t 1"), System.ComponentModel.Category("LEDLevelMeter")> _
    Public Property Led1Count() As Integer
        Get
            Return Me.LedCount1
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= 0
            If Not v_bl Then
                Me.LedCount1 = 0
            Else
                v_bl = Value <= 100
                If Not v_bl Then
                    Me.LedCount1 = 100
                Else
                    Me.LedCount1 = Value
                End If
            End If
            v_bl = ((Me.LedCount1 + Me.LedCount2) + Me.LedCount3) >= 1
            If Not v_bl Then
                Me.LedCount1 = 1
            End If
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter"), System.ComponentModel.Description("Number of Leds in middle area (0 to 32, default 6) Total Led count must be at lea" & "st 1")> _
    Public Property Led2Count() As Integer
        Get
            Return Me.LedCount2
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= 0
            If Not v_bl Then
                Me.LedCount2 = 0
            Else
                v_bl = Value <= 100
                If Not v_bl Then
                    Me.LedCount2 = 100
                Else
                    Me.LedCount2 = Value
                End If
            End If
            v_bl = ((Me.LedCount1 + Me.LedCount2) + Me.LedCount3) >= 1
            If Not v_bl Then
                Me.LedCount2 = 1
            End If
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Number of Leds in last area (0 to 32, default 4) Total Led count must be at least" & " 1"), System.ComponentModel.Category("LEDLevelMeter")> _
    Public Property Led3Count() As Integer
        Get
            Return Me.LedCount3
        End Get
        Set(ByVal Value As Integer)
            Dim v_bl As Boolean
            v_bl = Value >= 0
            If Not v_bl Then
                Me.LedCount3 = 0
            Else
                v_bl = Value <= 100
                If Not v_bl Then
                    Me.LedCount3 = 100
                Else
                    Me.LedCount3 = Value
                End If
            End If
            v_bl = ((Me.LedCount1 + Me.LedCount2) + Me.LedCount3) >= 1
            If Not v_bl Then
                Me.LedCount3 = 1
            End If
            CalcSize()
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Color of Leds in first area (Led on)"), System.ComponentModel.Category("LEDLevelMeter - Colors")> _
    Public Property Led1ColorOn() As System.Drawing.Color
        Get
            Return Me.LedColorOn1
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOn1 = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Color of Leds in middle area (Led on)"), System.ComponentModel.Category("LEDLevelMeter - Colors")> _
    Public Property Led2ColorOn() As System.Drawing.Color
        Get
            Return Me.LedColorOn2
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOn2 = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Color of Leds in last area (Led on)"), System.ComponentModel.Category("LEDLevelMeter - Colors")> _
    Public Property Led3ColorOn() As System.Drawing.Color
        Get
            Return Me.LedColorOn3
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOn3 = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter - Colors"), System.ComponentModel.Description("Color of Leds in first area (Led off)")> _
    Public Property Led1ColorOff() As System.Drawing.Color
        Get
            Return Me.LedColorOff1
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOff1 = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Category("LEDLevelMeter - Colors"), System.ComponentModel.Description("Color of Leds in middle area (Led off)")> _
    Public Property Led2ColorOff() As System.Drawing.Color
        Get
            Return Me.LedColorOff2
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOff2 = Value
            MyBase.Invalidate()
        End Set
    End Property
    <System.ComponentModel.Description("Color of Leds in last area (Led off)"), System.ComponentModel.Category("LEDLevelMeter - Colors")> _
    Public Property Led3ColorOff() As System.Drawing.Color
        Get
            Return Me.LedColorOff3
        End Get
        Set(ByVal Value As System.Drawing.Color)
            Me.LedColorOff3 = Value
            MyBase.Invalidate()
        End Set
    End Property
#End Region
End Class
'------------------------------------------------------------------------------

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #141 on: 20 Feb '14 - 15:30 »
 Add class enum MeterScale.vb

'-------------------------------
Public Enum MeterScale
#Region "MeterScale Fields"
    Analog = 0
    Log10 = 1
#End Region
End Enum
'-------------------------------

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #142 on: 20 Feb '14 - 15:32 »
Add class LEDLevelMeterDesigner.vb

'----------------------------------------------------------------
Friend Class LEDLevelMeterDesigner
    Inherits Windows.Forms.Design.ControlDesigner
#Region "LEDLevelMeterDesigner Constructors"
    Public Sub New()
        MyBase.New()
    End Sub
#End Region
#Region "LEDLevelMeterDesigner Methods"
    Protected Overloads Overrides Sub PostFilterProperties(ByVal properties As System.Collections.IDictionary)
        properties.Remove("AccessibleDescription")
        properties.Remove("AccessibleName")
        properties.Remove("AccessibleRole")
        properties.Remove("BackgroundImage")
        properties.Remove("BorderStyle")
        properties.Remove("Cursor")
        properties.Remove("RightToLeft")
        properties.Remove("UseWaitCursor")
        properties.Remove("AllowDrop")
        properties.Remove("AutoValidate")
        properties.Remove("ContextMenuStrip")
        properties.Remove("Enabled")
        properties.Remove("ImeMode")
        properties.Remove("TabStop")
        properties.Remove("ApplicationSettings")
        properties.Remove("DataBindings")
        properties.Remove("Tag")
        properties.Remove("GenerateMember")
        properties.Remove("Locked")
        properties.Remove("CausesValidation")
        properties.Remove("Anchor")
        properties.Remove("AutoSize")
        properties.Remove("AutoSizeMode")
        properties.Remove("Dock")
        properties.Remove("Margin")
        properties.Remove("MaximumSize")
        properties.Remove("MinimumSize")
        properties.Remove("Padding")
        properties.Remove("DockPadding")
        properties.Remove("AutoScrollMargin")
        properties.Remove("AutoScrollMinSize")
        properties.Remove("AutoScroll")
        properties.Remove("ForeColor")
        properties.Remove("Text")
    End Sub
#End Region
End Class
'----------------------------------------------------------------

Example:
Code: [Select]
Imports Un4seen.Bass
Public Class Form1
    Inherits Form
    Private Event SongStopping As EventHandler
    Private strm As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Me.Handle)
        Catch ex As Exception
            MsgBox(Bass.BASS_ErrorGetCode)
        End Try
    End Sub
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        Me.TopMost = True
        Me.Text = "BassPlayer"
        OpenFileDialog1.FileName = Nothing
        OpenFileDialog1.Filter = "Audio File(*.wav;*.mp3)|*.wav;*.mp3"
        Timer1.Interval = 35
        AddHandler Me.SongStopping, New EventHandler(AddressOf Me_SongStopping)
    End Sub
    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
            TextBox1.Clear()
            TextBox1.Text = OpenFileDialog1.SafeFileName
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        On Error Resume Next
        Bass.BASS_StreamFree(strm)
        strm = Bass.BASS_StreamCreateFile(TextBox1.Text, 0, 0, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MUSIC_LOOP)
        If strm Then
            Label1.Text = Utils.FixTimespan(Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetLength(strm)), "mm:ss")
            TrackBar1.Maximum = Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetLength(strm))
            TrackBar1.TickFrequency = TrackBar1.Maximum / 100 * 10
            Bass.BASS_ChannelPlay(strm, True)
            Timer1.Enabled = True
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim lev As Integer = Bass.BASS_ChannelGetLevel(strm)
        Label2.Text = BASS_Status()
        Label3.Text = Utils.FixTimespan(Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetPosition(strm)), "mm:ss")
        TrackBar1.Value = Bass.BASS_ChannelBytes2Seconds(strm, Bass.BASS_ChannelGetPosition(strm))
        LedLevelMeter1.Level = Utils.LowWord32(lev)
        LedLevelMeter2.Level = Utils.HighWord32(lev)
        InvokeSongStopped()
    End Sub
    Private Sub Me_SongStopping(ByVal sender As Object, ByVal e As EventArgs)
        Timer1.Enabled = False
        LedLevelMeter1.Level = 0
        LedLevelMeter2.Level = 0
        TrackBar1.Value = TrackBar1.Minimum
        Label3.Text = "00:00"
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Bass.BASS_ChannelSetPosition(strm, Bass.BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value))
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        On Error Resume Next
        Bass.BASS_ChannelStop(strm)
    End Sub
    Protected Overridable Sub InvokeSongStopped()
        If BASS_Status = "stopped" Then
            RaiseEvent SongStopping(Me, New EventArgs)
        End If
    End Sub
    Private ReadOnly Property BASS_Status() As String
        Get
            Dim v_state As String = Nothing
            Select Case Bass.BASS_ChannelIsActive(strm)
                Case BASSActive.BASS_ACTIVE_PAUSED
                    v_state = "paused"
                Case BASSActive.BASS_ACTIVE_PLAYING
                    v_state = "playing"
                Case BASSActive.BASS_ACTIVE_STALLED
                    v_state = "stalled"
                Case Else
                    v_state = "stopped"
            End Select
            Return v_state
        End Get
    End Property
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If MsgBox("Do you wanted to Exit?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, Nothing) = MsgBoxResult.Yes Then
            Bass.BASS_Free()
            e.Cancel = False
        Else
            e.Cancel = True
        End If
    End Sub
End Class

Get Sample Project LEDLevelMeter User control Library DLL Click here
« Last Edit: 20 Feb '14 - 17:32 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #143 on: 21 Feb '14 - 03:37 »
LedLevelMeter, Using..  BuckSoft.DirectSound.dll User Component ;D Download Clickhere

You must references DirectX.dll, Direct3D.dll and DirectSound.dll

Example: Sound Speakers , It work when play sound.
Code: [Select]
Imports BuckSoft.DirectSound
Public Class Form1
    Private LedMeter As New AnalogSignalMeter
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LedMeter.LedWidth = 12
        LedMeter.LedHeight = 1
        LedMeter.Location = New Point(130, 60)
        LedMeter.LowLedColor = Color.LawnGreen
        LedMeter.LowLedCount = 30
        LedMeter.MidLedCount = 15
        LedMeter.HighLedCount = 5
        LedMeter.DisplayOrientation = AnalogSignalMeter.Orientation.VerticalReverse
        LedMeter.SampleFrequencyMilliseconds = 50
        LedMeter.StartMeter()
        Me.Controls.Add(LedMeter)
    End Sub
End Class


« Last Edit: 21 Feb '14 - 08:58 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #144 on: 22 Feb '14 - 07:09 »
Modify bass.netDLL functions , For it essy using.. ;D

You must add bass.dll in the debug folder and -
reference bass.net.dll and Import Un4Seen.Bass now.

Initialize Bass, For load select drivers (-1 or 1) and set freq (44100 or other)
Added function to the FormLoad event. 

Init BASS
Code: [Select]
Public Shared Sub InitializeBass(ByVal hForm As Form)
        Try
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, hForm.Handle)
        Catch ex As Exception
            MsgBox(Bass.BASS_ErrorGetCode)
        End Try
        Return
    End Sub
--------------------------------------------------------------------------------
Open a song file on the TextBox.
Code: [Select]
Public Shared ReadOnly Property OpenSound(ByVal handle As Integer, ByVal FileName As String, ByVal Repeat As Boolean) As Integer
        Get
            Dim v_stream As Integer = Nothing
            Try
                Bass.BASS_StreamFree(handle)
                Select Case Repeat
                    Case True
                        v_stream = Bass.BASS_StreamCreateFile(FileName, 0, 0, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_MUSIC_LOOP)
                    Case Else
                        v_stream = Bass.BASS_StreamCreateFile(FileName, 0, 0, BASSFlag.BASS_DEFAULT)
                End Select
            Catch ex As Exception
                MsgBox(Bass.BASS_ErrorGetCode)
            End Try
            Return v_stream
        End Get
    End Property
-------------------------------------------------------------------------------
Open song files on the ListBox (PlayList)
Code: [Select]
Public Shared Sub PlayListCreated(ByVal hForm As Form)
        newList.Size = hForm.Size
        newList.Location = hForm.Location 'Added function to FormLoad.
        hForm.Controls.Add(newList)
    End Sub
    Public Shared Sub PlayListAppendItems(ByVal FileNames As String(), ByVal cList As ListBox)
        For Each files As String In FileNames
            newList.Items.Add(files)
            cList.Items.Add(System.IO.Path.GetFileName(files))
        Next
        If cList.SelectedIndex = -1 Then 'Added function on the open button.
            cList.SetSelected(0, True)
        End If
        Return
    End Sub
    Public Shared ReadOnly Property PlayListSelectedItem(ByVal cList As ListBox) As String
        Get
            Dim ind As Integer = cList.SelectedIndex
            newList.SetSelected(ind, True) 
            Return newList.SelectedItem 'Item text on the listbox to selected.
        End Get
    End Property
-----------------------------------------------------------------------
Example : Load files playlist and set select item to playing
Code: [Select]
Private Sub ButtonLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLoad.Click
        OpenFileDialog1.Multiselect = True
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PlayListAppendItems(OpenFileDialog1.FileNames, ListBox1)
        End If
    End Sub
    Private Sub ButtonPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPlay.Click
        On Error Resume Next
        strm = OpenSound(strm, PlayListSelectedItem(ListBox1), False)
        If strm Then
            PlaySound(strm, True)
        End If
    End Sub
   
« Last Edit: 22 Feb '14 - 09:24 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #145 on: 22 Feb '14 - 07:56 »
Playing song file to selected.
Code: [Select]
Public Shared Sub PlaySound(ByVal handle As Integer, ByVal restart As Boolean)
        Try
            Bass.BASS_ChannelPlay(handle, restart)
        Catch ex As Exception
            MsgBox(Bass.BASS_ErrorGetCode)
        End Try
        Return
    End Sub
-------------------------------------------
Example : Playing selected on the play button, For open song file.

Code: [Select]
  Private Sub ButtonOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpen.Click
        OpenFileDialog1.Multiselect = False
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = OpenFileDialog1.SafeFileName
        End If
    End Sub
    Private Sub ButtonPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPlay.Click
        On Error Resume Next
        strm = BassMethods.OpenSound(strm, TextBox1.Text, False)
        If strm Then
            PlaySound(strm, True)
        End If
    End Sub
==============================================================
Download : BassPlayer sample project Click here

« Last Edit: 22 Feb '14 - 09:49 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #146 on: 7 Mar '14 - 13:07 »
Created Sound Player With LibZPlay.net.dll ;D Download Click here

Example:
Code: [Select]
Imports System.Windows.Forms
Imports libZPlay.net
Public Class Form1
    Inherits Form
    Private WithEvents txtFilename As TextBox
    Private WithEvents trackPos As TrackBar
    Private WithEvents btnOpen As Button
    Private WithEvents btnPlay As Button
    Private WithEvents btnPause As Button
    Private WithEvents btnStop As Button
    Private WithEvents timer1 As Timer
    Private lblDoration As Label
    Private lblPosition As Label
    Private lblStatus As Label
    Private leftvu As ProgressBar
    Private rightvu As ProgressBar
    Private fDlg As OpenFileDialog
    Private player As ZPlay
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        InitializeComponent()
        Me.Text = "LibZPlayer"
        Me.Height = 160
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        player = New ZPlay
        trackPos = New TrackBar
        trackPos.SetBounds(40, 40, 200, 20)
        trackPos.AutoSize = False
        txtFilename = New TextBox
        txtFilename.SetBounds(5, 6, 200, 23)
        lblDoration = New Label
        lblDoration.Text = "00:00"
        lblDoration.Location = New Point(5, 40)
        lblDoration.AutoSize = True
        lblPosition = New Label
        lblPosition.Text = "00:00"
        lblPosition.Location = New Point(240, 40)
        lblPosition.AutoSize = True
        leftvu = New ProgressBar
        rightvu = New ProgressBar
        leftvu.SetBounds(5, 100, 280, 10)
        rightvu.SetBounds(5, 111, 280, 10)
        lblStatus = New Label
        lblStatus.Text = "stopped"
        lblStatus.Location = New Point(120, 30)
        lblStatus.AutoSize = True
        btnOpen = New Button
        btnOpen.Text = "Open"
        btnOpen.Location = New Point(210, 5)
        btnOpen.Cursor = Cursors.Hand
        btnPlay = New Button
        btnPlay.Text = "Play"
        btnPlay.Location = New Point(5, 70)
        btnPlay.Cursor = Cursors.Hand
        btnPause = New Button
        btnPause.Text = "Pause"
        btnPause.Location = New Point(110, 70)
        btnPause.Cursor = Cursors.Hand
        btnStop = New Button
        btnStop.Text = "Stop"
        btnStop.Location = New Point(210, 70)
        btnStop.Cursor = Cursors.Hand
        Me.Controls.AddRange(New Control() {txtFilename, lblDoration, lblPosition, lblStatus, leftvu, rightvu, trackPos, btnOpen, btnPlay, btnPause, btnStop})
        fDlg = New OpenFileDialog
        fDlg.FileName = Nothing
        fDlg.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        timer1 = New Timer
        timer1.Interval = 35
    End Sub
    Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOpen.Click
        If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            txtFilename.Text = fDlg.SafeFileName
        End If
    End Sub
    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlay.Click
        If txtFilename.Text <> Nothing Then
            player.Close()
            player.OpenFile(txtFilename.Text, TStreamFormat.sfAutodetect)
            Dim StreamInfo As New TStreamInfo()
            player.GetStreamInfo(StreamInfo)
            lblDoration.Text = Format(StreamInfo.Length.hms.minute, "00") & ":" & Format(StreamInfo.Length.hms.second, "00")
            trackPos.Maximum = CInt(Fix(StreamInfo.Length.sec))
            trackPos.TickFrequency = CInt(trackPos.Maximum / 100 * 10)
            player.StartPlayback()
            If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
            timer1.Enabled = True
        End If
    End Sub
    Private Sub btnPause_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPause.Click
        If txtFilename.Text <> Nothing Then
            Select Case btnPause.Text
                Case "Pause"
                    player.PausePlayback()
                    btnPause.Text = "Resume"
                Case Else
                    player.ResumePlayback()
                    btnPause.Text = "Pause"
            End Select
        End If
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnStop.Click
        player.StopPlayback()
        If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
    End Sub
    Private Sub trackPos_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles trackPos.Scroll
        Dim newpos As New TStreamTime()
        newpos.sec = CUInt(trackPos.Value)
        player.Seek(TTimeFormat.tfSecond, newpos, TSeekMethod.smFromBeginning)
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
        Dim pos As New TStreamTime()
        player.GetPosition(pos)
        trackPos.Value = CInt(Fix(pos.sec))
        lblPosition.Text = Format(pos.hms.minute, "00") & ":" & Format(pos.hms.second, "00")
        Dim left As Integer = 0
        Dim right As Integer = 0
        player.GetVUData(Left, Right)
        leftvu.Value = Left
        rightvu.Value = Right
        lblStatus.Text = Status()
    End Sub
    Private Sub txtFilename_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtFilename.TextChanged
        If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
    End Sub
    Private ReadOnly Property Status() As String
        Get
            Dim State As New TStreamStatus()
            Dim st As String = Nothing
            player.GetStatus(State)
            If State.fPlay Then
                st = "playing"
            ElseIf State.fPause Then
                st = "paused"
            Else
                st = "stopped"
            End If
            Return st
        End Get
    End Property
End Class
« Last Edit: 7 Mar '14 - 20:04 by sak2005 »

shakydd

  • Posts: 36
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #147 on: 7 Mar '14 - 14:19 »
:-) I couldn't see the link here and didn't know if this was related to my post around ZPlay, etc :-) Have you ever thought of putting all your VB.NET code into one bigger, wider project as a massive sample?

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #148 on: 7 Mar '14 - 19:59 »
:-) I couldn't see the link here and didn't know if this was related to my post around ZPlay, etc :-) Have you ever thought of putting all your VB.NET code into one bigger, wider project as a massive sample?

Sorry ::) I'm slow Posts

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net (vb2008, vc#, vc++)
« Reply #149 on: 7 Mar '14 - 20:09 »
Using PlaylistDLL in the LibZPlayer ;D

Example:
Code: [Select]
Imports System.Windows.Forms
Imports libZPlay.net
Imports PlayList.PL
Public Class Form1
    Inherits Form
    Private WithEvents txtFilename As TextBox
    Private WithEvents trackPos As TrackBar
    Private WithEvents btnOpen As Button
    Private WithEvents btnPlay As Button
    Private WithEvents btnPause As Button
    Private WithEvents btnStop As Button
    Private WithEvents timer1 As Timer
    Private lblDoration As Label
    Private lblPosition As Label
    Private lblStatus As Label
    Private leftvu As ProgressBar
    Private rightvu As ProgressBar
    Private fDlg As OpenFileDialog
    Private player As ZPlay
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        InitializeComponent()
        Me.Text = "LibZPlayer"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        player = New ZPlay
        trackPos = New TrackBar
        trackPos.SetBounds(40, 40, 200, 20)
        trackPos.AutoSize = False
        txtFilename = New TextBox
        txtFilename.SetBounds(5, 6, 200, 23)
        lblDoration = New Label
        lblDoration.Text = "00:00"
        lblDoration.Location = New Point(5, 40)
        lblDoration.AutoSize = True
        lblPosition = New Label
        lblPosition.Text = "00:00"
        lblPosition.Location = New Point(240, 40)
        lblPosition.AutoSize = True
        leftvu = New ProgressBar
        rightvu = New ProgressBar
        leftvu.SetBounds(5, 100, 280, 10)
        rightvu.SetBounds(5, 111, 280, 10)
        lblStatus = New Label
        lblStatus.Text = "stopped"
        lblStatus.Location = New Point(120, 30)
        lblStatus.AutoSize = True
        btnOpen = New Button
        btnOpen.Text = "Open"
        btnOpen.Location = New Point(210, 5)
        btnOpen.Cursor = Cursors.Hand
        btnPlay = New Button
        btnPlay.Text = "Play"
        btnPlay.Location = New Point(5, 70)
        btnPlay.Cursor = Cursors.Hand
        btnPause = New Button
        btnPause.Text = "Pause"
        btnPause.Location = New Point(110, 70)
        btnPause.Cursor = Cursors.Hand
        btnStop = New Button
        btnStop.Text = "Stop"
        btnStop.Location = New Point(210, 70)
        btnStop.Cursor = Cursors.Hand
        Me.Controls.AddRange(New Control() {txtFilename, lblDoration, lblPosition, lblStatus, leftvu, rightvu, trackPos, btnOpen, btnPlay, btnPause, btnStop})
        fDlg = New OpenFileDialog
        fDlg.FileName = Nothing
        fDlg.Filter = "Audio Files(*.wav;*.mp3)|*.wav;*.mp3|All Files(*.*)|*.*"
        fDlg.Multiselect = True
        timer1 = New Timer
        timer1.Interval = 35
        ListBox1.SetBounds(12, 133, 268, 121)
        ListBox1.HorizontalScrollbar = True
        PlayListCreated(Me, ListBox1)
    End Sub
    Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOpen.Click
        If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            PlayListAppendItems(fDlg.FileNames)
        End If
    End Sub
    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlay.Click
        If PlayListSelectedItem() <> String.Empty Then
            player.Close()
            txtFilename.Text = ListBox1.SelectedItem
            player.OpenFile(PlayListSelectedItem(), TStreamFormat.sfAutodetect)
            Dim StreamInfo As New TStreamInfo()
            player.GetStreamInfo(StreamInfo)
            lblDoration.Text = Format(StreamInfo.Length.hms.minute, "00") & ":" & Format(StreamInfo.Length.hms.second, "00")
            trackPos.Maximum = CInt(Fix(StreamInfo.Length.sec))
            trackPos.TickFrequency = CInt(trackPos.Maximum / 100 * 10)
            player.StartPlayback()
            If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
            timer1.Enabled = True
        End If
    End Sub
    Private Sub btnPause_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPause.Click
        If txtFilename.Text <> Nothing Then
            Select Case btnPause.Text
                Case "Pause"
                    player.PausePlayback()
                    btnPause.Text = "Resume"
                Case Else
                    player.ResumePlayback()
                    btnPause.Text = "Pause"
            End Select
        End If
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnStop.Click
        player.StopPlayback()
        If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
    End Sub
    Private Sub trackPos_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles trackPos.Scroll
        Dim newpos As New TStreamTime()
        newpos.sec = CUInt(trackPos.Value)
        player.Seek(TTimeFormat.tfSecond, newpos, TSeekMethod.smFromBeginning)
    End Sub
    Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
        Dim pos As New TStreamTime()
        player.GetPosition(pos)
        trackPos.Value = CInt(Fix(pos.sec))
        lblPosition.Text = Format(pos.hms.minute, "00") & ":" & Format(pos.hms.second, "00")
        Dim left As Integer = 0
        Dim right As Integer = 0
        player.GetVUData(Left, Right)
        leftvu.Value = Left
        rightvu.Value = Right
        lblStatus.Text = Status()
    End Sub
    Private Sub txtFilename_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtFilename.TextChanged
        If Strings.InStr(btnPause.Text, "Resume") Then btnPause.Text = "Pause"
    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        On Error Resume Next
        btnPlay.PerformClick()
    End Sub
    Private ReadOnly Property Status() As String
        Get
            Dim State As New TStreamStatus()
            Dim st As String = Nothing
            player.GetStatus(State)
            If State.fPlay Then
                st = "playing"
            ElseIf State.fPause Then
                st = "paused"
            Else
                st = "stopped"
            End If
            Return st
        End Get
    End Property
End Class
« Last Edit: 7 Mar '14 - 20:33 by sak2005 »