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

sak2005

  • Posts: 1007
Visual Studio : VS2010
OS : WindowsXP SP3
Programmer : sak2005 (thailand)

Example:

Code: [Select]
Public Class Form1

    Private Declare Function BASS_Init Lib "bass.dll" (ByVal device As Integer, ByVal freq As UInteger, ByVal flags As UInteger, ByVal win As IntPtr, ByVal clsid As UInteger) As Boolean
    Private Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As IntPtr) As Integer
    Private Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    Private Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    Private Declare Function BASS_ChannelPause Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    Private Declare Function BASS_StreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr
    Private BASS_STREAM_PRESCAN As UInteger = &H20000
    Private BASS_STREAM_AUTOFREE As UInteger = &H40000
    Private stream As IntPtr

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BASS_Init(-1, 44100, 1024, IntPtr.Zero, Nothing)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        stream = BASS_StreamCreateFile(False, TextBox1.Text, 0, 0, 0, 0, BASS_STREAM_AUTOFREE Or BASS_STREAM_PRESCAN)
        Try
            BASS_ChannelPlay(stream, True)
            Timer1.Enabled = True
        Catch
        End Try
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim valZero As Integer = 0
        BASS_ChannelStop(stream, True)
        ProgressBar1.Value = valZero
        ProgressBar2.Value = valZero
        Timer1.Enabled = False
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        OpenFileDialog1.Filter = "Mp3 File(*.mp3)|*.mp3"
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = OpenFileDialog1.FileName
        End If
    End Sub
    
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim level, left, right As Integer
        level = BASS_ChannelGetLevel(stream)
        left = LoWord(level)
        right = HiWord(level)
        Try
            ProgressBar1.Value = Math.Round(left / 100 / 100 * 20)
            ProgressBar2.Value = Math.Round(right / 100 / 100 * 20)
        Catch
        End Try
    End Sub

    Private Function LoWord(ByVal lparam As Long) As Long
        LoWord = lparam And &HFFFF&
    End Function

    Private Function HiWord(ByVal lparam As Long) As Long
        If lparam < 0 Then
            HiWord = (lparam \ &H10000 - 1) And &HFFFF&
        Else
            HiWord = lparam \ &H10000
        End If
    End Function
End Class
==============================================================
Example: For bass register with out splash screen.  

You wanted contect: Un4Seen


Code: [Select]
ports System
Imports Un4seen.Bass

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Un4seen.Bass.BassNet.Registration("test@gmail.com", "2XXXXXXXXXXXXXX")
        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
        Me.Text = "Basic BASS Audio"
        'Me.Size = New Size(300, 130)
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        Me.TopMost = True
        Me.CenterToScreen()
        Button1.Text = "Open"
        Button2.Text = "Pause"
        Button3.Text = "Stop"
        Button1.Cursor = Cursors.Hand
        Button2.Cursor = Cursors.Hand
        Button3.Cursor = Cursors.Hand
        Label1.Text = "L"
        Label2.Text = "R"
        TextBox1.Text = 0
        TextBox2.Text = 0
    End Sub

    Private stream As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Bass.BASS_Start()
        With OpenFileDialog1
            .Title = "Open"
            .FileName = ""
            .Filter = "Song files(*.mp3)|*.mp3"
            .RestoreDirectory = 2
        End With
        Select Case Button1.Text
            Case "Open"
                If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    stream = Bass.BASS_StreamCreateFile(OpenFileDialog1.FileName, 0, 0, BASSFlag.BASS_DEFAULT)
                    If stream <> 0 Then
                        Button1.Text = "Play"
                        Exit Sub
                    End If
                End If
            Case "Play"
                Bass.BASS_ChannelPlay(stream, False)
                Timer1.Enabled = True
        End Select
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        If Bass.BASS_ChannelPause(stream) Then
            ProgressBar1.Value = 0
            ProgressBar2.Value = 0
            TextBox1.Text = 0
            TextBox2.Text = 0

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Bass.BASS_Stop() Then
            ProgressBar1.Value = 0
            ProgressBar2.Value = 0
            TextBox1.Text = 0
            TextBox2.Text = 0
            Timer1.Enabled = False
            Button1.Text = "Open"
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim level As Integer = Bass.BASS_ChannelGetLevel(stream)
        Dim left As Double = Utils.LowWord32(level)
        Dim right As Double = Utils.HighWord32(level)
        ProgressBar1.Value = Math.Round(left / 200 / 2)
        ProgressBar2.Value = Math.Round(right / 200 / 2)
        Timer1.Interval = 50
    End Sub
End Class

« Last Edit: 12 Oct '15 - 09:58 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #1 on: 17 Jun '12 - 02:07 »
Example: BassClass & BassForm VB.NET Programming

BassClass:
Code: [Select]
Imports System.Runtime.InteropServices
Public Class BassClass
    'Declare Function BASS_Init Lib "bass.dll" (ByVal device As Integer, ByVal freq As UInteger, ByVal flags As UInteger, ByVal win As IntPtr, ByVal clsid As UInteger) As Boolean
    'Declare Function BASS_StreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr
    'Private Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As IntPtr, ByVal mode As Single()) As Integer
    'Private Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    'Private Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    Public Shared Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BassInit, ByVal win As System.IntPtr) As Boolean
        Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero)
    End Function

    <DllImport("bass.dll")> _
    Private Shared Function BASS_Init(ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BassInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Shared Function BASS_StreamCreateFile(ByVal mem As Boolean, ByVal file As String, ByVal offset As UInteger, ByVal offsethigh As UInteger, ByVal length As UInteger, ByVal lengthhigh As UInteger, ByVal flags As UInteger) As IntPtr
    End Function

    <DllImport("bass.dll", EntryPoint:="BASS_Init", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _
    Private Shared Function BASS_InitGuid(<MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BassInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.Guid) As Boolean
    End Function

    <DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile")> _
    Public Shared Function BASS_StreamCreateFileMemory(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

    <DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=CharSet.[Auto], SetLastError:=False)> _
    Private Shared Function BASS_StreamCreateFileUnicode(ByVal A_0 As Boolean, ByVal A_1 As String, ByVal A_2 As Long, ByVal A_3 As Long, ByVal A_4 As BASSFlag) As Integer
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetLevel(ByVal handle As Integer) As Integer
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelPlay(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelStop(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelPause(ByVal handle As IntPtr, ByVal restart As Boolean) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetPosition(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetLength(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelBytes2Seconds(ByVal handle As Integer, ByVal pos As Long) As Double
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelSeconds2Bytes(ByVal handle As Integer, ByVal pos As Double) As Long
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelSetPosition(ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_GetVolume() As Single
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_SetVolume(ByVal A_0 As Single) As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_Free() As Boolean
    End Function

    <DllImport("bass.dll")> _
    Public Shared Function BASS_Start() As Boolean
    End Function

    Public Shared Function HighWord(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function

    Public Shared Function LowWord(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function

    Public Shared Function BASS_StreamCreateFileA(ByVal [file] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
        flags = flags Or BASSFlag.BASS_UNICODE
        Return BASS_StreamCreateFileUnicode(False, [file], offset, length, flags)
    End Function

    Public Shared Function SecToTime(ByVal Seconds As Integer, Optional ByRef rHour As Integer = 0, Optional ByRef rMinute As Integer = 0, Optional ByRef rSecond As Integer = 0) As String
        rHour = (Seconds \ 3600)
        rMinute = (Seconds - (rHour * 3600)) \ 60
        rSecond = (Seconds - (rHour * 3600) - (rMinute * 60))
        SecToTime = Format(rMinute, "00") & ":" & Format(rSecond, "00")
    End Function
    <Flags()> _
    Public Enum BassInit
        BASS_DEVICE_DEFAULT = 0
        BASS_DEVICE_8BITS = 1
        BASS_DEVICE_MONO = 2
        BASS_DEVICE_LATENCY = 256
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS = 2048
        BASS_DEVICE_NOSPEAKER = 4096
    End Enum
    <Flags()> _
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_SAMPLE_FLOAT = 256
        BASS_STREAM_PRESCAN = 131072
        BASS_STREAM_AUTOFREE = 262144
        BASS_UNICODE = -2147483648
    End Enum
    <Flags()> _
    Public Enum BASSMode
        BASS_POS_BYTES = 0
        BASS_POS_MUSIC_ORDERS = 1
        BASS_POS_MIDI_TICK = 2
    End Enum
End Class
BassForm:
Code: [Select]
Imports WindowsApplication1.BassClass
Public Class BassForm
    Public Declare Function SendMessageW Lib "user32" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    Public Const APPCOMMAND_VOLUME_MUTE_DOWN As Integer = &HA0000
    Public Const APPCOMMAND_VOLUME_MUTE As Integer = &H80000
    Public Const WM_APPCOMMAND As Integer = &H319
    Public stream As Integer
    Public ProgressZero As Integer
    Public percent As Double

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TrackBar2.Value = 10
        Me.Size = New Size(367, 200)
        Me.Text = "BASS Sound Sample"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        BASS_SetVolume(0)
        Button1.Text = "Open"
        Button2.Text = "Play"
        Button3.Text = "Stop"
        Button4.Text = "Mute"
        Label1.Text = "0%"
        Label2.Text = "00:00"
        Label3.Text = "00:00"
        Button1.Cursor = Cursors.Hand
        Button2.Cursor = Cursors.Hand
        Button3.Cursor = Cursors.Hand
        Button4.Cursor = Cursors.Hand
        Me.CenterToScreen()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If percent = 0 Then
            If stream <> 0 Then
                BASS_ChannelPlay(stream, True)
                Timer1.Enabled = True
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        percent = 0
        With OpenFileDialog1
            .Filter = ("SongFile(*.mp3)|*.mp3")
            .FileName = ""
        End With
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            BASS_Free()
            ProgressBar1.Value = ProgressZero
            ProgressBar2.Value = ProgressZero
            BASS_Init(-1, 44100, BassInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
            stream = BASS_StreamCreateFileA(OpenFileDialog1.FileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_STREAM_PRESCAN)
            If stream Then
                BASS_GetVolume()
                Dim len As Long = BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTES)
                Dim pos As Long = BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES)
                Dim totaltime As Double = BASS_ChannelBytes2Seconds(stream, len)
                Dim elapsedtime As Double = BASS_ChannelBytes2Seconds(stream, pos)
                Dim remainingtime As Double = totaltime - elapsedtime
                Label2.Text = SecToTime(remainingtime, remainingtime, remainingtime)
            End If
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If stream <> 0 Then
            BASS_Free()
            BASS_ChannelStop(stream, True)
            ProgressBar1.Value = ProgressZero
            ProgressBar2.Value = ProgressZero
            TrackBar1.Value = 0
            Label1.Text = "0%"
            Label2.Text = "00:00"
            Label3.Text = "00:00"
            Timer1.Enabled = False
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim level As Integer = BASS_ChannelGetLevel(stream)
        Dim left As Integer = LowWord(level)
        Dim right As Integer = HighWord(level)
        Dim len As Long = BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTES)
        Dim pos As Long = BASS_ChannelGetPosition(stream, BASSMode.BASS_POS_BYTES)
        Dim totaltime As Double = BASS_ChannelBytes2Seconds(stream, len)
        Dim elapsedtime As Double = BASS_ChannelBytes2Seconds(stream, pos)
        Dim remainingtime As Double = totaltime - elapsedtime
        Label3.Text = SecToTime(remainingtime, remainingtime, remainingtime)
        percent = Math.Round((pos / len) * 100, 0)
        TrackBar1.Value = percent
        Label1.Text = String.Concat(percent, "%")
        If TrackBar1.Value >= 100 Then
            BASS_ChannelPlay(stream, True)
            'BASS_ChannelPause(stream, True)
        End If
        Try
            ProgressBar1.Value = (Math.Round(left, 3) / 1000 * 3)
            ProgressBar2.Value = (Math.Round(right, 3) / 1000 * 3)
            Timer1.Interval = 30
        Catch
        End Try
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Select Case Button4.Text
            Case "Mute"
                SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_MUTE, IntPtr))
                Button4.Text = "UnMute"
                Button4.ForeColor = Color.Red
            Case "UnMute"
                SendMessageW(Me.Handle, WM_APPCOMMAND, Me.Handle, CType(APPCOMMAND_VOLUME_MUTE, IntPtr))
                Button4.Text = "Mute"
                Button4.ForeColor = Color.Black
        End Select
    End Sub

    Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        BASS_SetVolume(TrackBar2.Value / 10).ToString()
    End Sub
End Class



« Last Edit: 22 Jun '12 - 06:23 by sak2005 »

gnag

  • Posts: 160
Re: Direct bass : Vb.net
« Reply #2 on: 17 Jun '12 - 18:02 »
Its nice that you share your code with us by why would someone need to implement a .NET Wrapper for BASS if there is already the existing, working and well-documented BASS.NET Component existing which is basically already what you started?

But nevertheless it looks like you know about what you are doing.

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #3 on: 22 Jun '12 - 06:24 »
Try with windows multimedia winMM modify.

Download: DLL and Sample project. Click here
----------------------------------------------------------------
Download: WindowsMediaLib Sample project Click here
----------------------------------------------------------------
Download: MediaControl.dll & Sample project Click here
-----------------------------------------------------------------------
Download: Basic MCI Sound Click here
---------------------------------------------------------------------------------
Download: Basic nBASS Programming Click here
« Last Edit: 27 Jun '12 - 02:02 by sak2005 »

gnag

  • Posts: 160
Re: Direct bass : Vb.net
« Reply #4 on: 23 Jun '12 - 21:17 »
The Peakmeter looks nice, how did you made that out of which Controls ?

However when I open a Music (MP3 File) and try to click Play it displays me this message and I only hear some distorted seconds of Playback:


sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #5 on: 24 Jun '12 - 04:18 »
You must select song file before click play button.

If not select song file. Message will show.

If  you wanted modify. Skip command message now.

Example: //MessageBox.Show("คุณยังไม่ได้เลือกเพลง");
--------------------------------------------------
[Basic Programming From Thailand]
« Last Edit: 24 Jun '12 - 04:50 by sak2005 »

gnag

  • Posts: 160
Re: Direct bass : Vb.net
« Reply #6 on: 24 Jun '12 - 17:25 »
I selected a File like I said and it did display that Message !

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #7 on: 27 Jun '12 - 11:00 »
nBASS Level Progress Meter

Code: [Select]
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim posBytes As Integer = BASS_ChannelGetPosition(strm)
        Dim lenBytes As Integer = BASS_StreamGetLength(strm)
        lblPos.Text = "Position: " & BASS_ChannelBytes2Seconds(strm, posBytes) & " / " & BASS_ChannelBytes2Seconds(strm, lenBytes)
        barPos.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm))
        If posBytes = lenBytes Then BASS_StreamPlay(strm, 0, 0)
        Dim levelL As Integer = BASS_ChannelGetLevel(strm)
        Dim levelR As Integer = BASS_ChannelGetLevel(strm)
        Dim peakL As Integer = GetLoWord(levelL)
        Dim peakR As Integer = GetHiWord(levelR)
        Try
            ProgressBar1.Value = Math.Round(peakL) / 1.3
            ProgressBar2.Value = Math.Round(peakR) / 1.3
            Timer1.Interval = 35
        Catch
        End Try
    End Sub
=======================================================
nBASS Mouse Slide Scroll Position

Code: [Select]
Private Sub barPos_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barPos.Scroll
        BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, barPos.Value))
    End Sub
========================================================
nBASS Mouse Slide Srcoll Volume

Code: [Select]
Private Sub barVol_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barVol.Scroll
        BASS_SetVolume(barVol.Value)
        lblVol.Text = "Volume: " & barVol.Value & "%"
    End Sub
==========================================================
nBASS Mouse Slide Scroll Volume Balance

You must set properties barBal.Minimum = -100

Code: [Select]
Private Sub barBal_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles barBal.Scroll
        Dim a As String = Nothing
        BASS_ChannelSetAttributes(strm, -1, -1, barBal.Value)
        Select Case barBal.Value
            Case Is < 0
                lblBal.Text = "Balance: Left: " & barBal.Value & "%"
            Case Is > 0
                lblBal.Text = "Balance: Right: " & barBal.Value & "%"
            Case Else
                lblBal.Text = "Balance: Center: " & barBal.Value & "%"
        End Select
    End Sub
« Last Edit: 27 Jun '12 - 13:11 by sak2005 »

Gamo

  • Posts: 97
Re: Direct bass : Vb.net
« Reply #8 on: 27 Jun '12 - 13:52 »
Why not put your project file?

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #9 on: 27 Jun '12 - 16:30 »
Project Files is Download

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #10 on: 27 Jun '12 - 18:15 »
Info: nbass.dll has 2 versions. 0.9.6.1 and 1.8.0.0 ..It's bass.net.dll ..Create from vb.net
       You must select to use.
        bass.dll  It's Lib.dll ..Create from C++ Support nbass 2 versions.
------------------------------------------------------------------
Tip: If you create program project and before run debug
       you must add file.net.dll and file.dll  in to debug folder of your the project.
       The writting code made 2 ways
        1. Create Class or Module
        2. Referents file.net.dll into the Visual Studio.       

« Last Edit: 27 Jun '12 - 18:38 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #11 on: 27 Jun '12 - 18:54 »
Easy bass Sample : Three in OneTouchButton (Open , Play and Stop)

Unuse nBass.net.dll

Add bass.dll in to the debug folder.

Code: [Select]
Public Class Form1
    Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer
    Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer
    Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer
    Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer
    Public strm As Integer
   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case Button1.Text
            Case "Open"
                Dim fileDLG As New OpenFileDialog()
                With fileDLG
                    .FileName = ""
                    .Filter = "Song file(*.mp3)|*.mp3"
                End With
                If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32)
                    BASS_ChannelStart()
                    strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0)
                    Button1.Text = "Play"
                End If
            Case "Play"
                If strm <> 0 Then
                    BASS_ChannelPlay(strm, 0, 0)
                    Button1.Text = "Stop"
                End If
            Case "Stop"
                If strm <> 0 Then
                    BASS_ChannelStop(strm)
                    Button1.Text = "Open"
                End If
        End Select
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        Button1.Text = "Open"
    End Sub
End Class
« Last Edit: 28 Jun '12 - 04:05 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #12 on: 28 Jun '12 - 04:16 »
Step by step sample: Set TrackBar sound file position.

Add TrackBar1 and Timer1 on the form.

Code: [Select]
Public Class Form1
    Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer
    Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer
    Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer
    Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer
    Public strm As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        TrackBar1.TickStyle = TickStyle.None
        Button1.Text = "Open"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case Button1.Text
            Case "Open"
                Dim fileDLG As New OpenFileDialog()
                With fileDLG
                    .FileName = ""
                    .Filter = "Song file(*.mp3)|*.mp3"
                End With
                If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32)
                    BASS_ChannelStart()
                    strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0)
                    Button1.Text = "Play"
                End If
            Case "Play"
                If strm <> 0 Then
                    BASS_ChannelPlay(strm, 0, 0)
                    Button1.Text = "Stop"
                    Timer1.Enabled = True
                    TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm))
                End If
            Case "Stop"
                If strm <> 0 Then
                    BASS_ChannelStop(strm)
                    Button1.Text = "Open"
                    Timer1.Enabled = False
                End If
        End Select
    End Sub

   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim sLen As Long = BASS_ChannelGetLength(strm)
        Dim sPos As Long = BASS_ChannelGetPosition(strm)
        Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen)
        Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos)
        TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm))
        If cPos = cLen Then
            BASS_ChannelPlay(strm, 0, 0)
        End If
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value))
    End Sub
End Class
« Last Edit: 28 Jun '12 - 06:50 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #13 on: 28 Jun '12 - 07:02 »
Tip: TimeSpanEx function. Using for add systemTime and counter Timer or other.

Code: [Select]
Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer)
        Dim retValue As New TimeSpan(hour, min, sec)
        Return retValue.ToString()
End Function
==================================================
Example: SystemTime

Add Timer1 on the form.

Code: [Select]
Public Class Form1

    Dim Label1 As New Label()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(Label1)
        Label1.Location = New Point(100, 100)
        Label1.Text = TimeSpanEx(0, 0, 0)
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim hh As Integer = Now.Hour
        Dim mm As Integer = Now.Minute
        Dim ss As Integer = Now.Second
        Label1.Text = TimeSpanEx(hh, mm, ss)
    End Sub

    Public Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer)
        Dim retValue As New TimeSpan(hour, min, sec)
        Return retValue.ToString()
    End Function
End Class
==================================================
Example: Counter Timer
Code: [Select]
Public Class Form1

    Dim Label1 As New Label()
    Dim s As Integer = 0
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(Label1)
        Label1.Location = New Point(100, 100)
        Label1.Text = TimeSpanEx(0, 0, 0)
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim h As Integer = Nothing
        Dim m As Integer = Nothing
        s += 1
        Label1.Text = TimeSpanEx(h, m, s)
        Timer1.Interval = 1000
    End Sub

    Public Function TimeSpanEx(ByVal hour As Integer, ByVal min As Integer, ByVal sec As Integer)
        Dim retValue As New TimeSpan(hour, min, sec)
        Return retValue.ToString()
    End Function
End Class
« Last Edit: 30 Jun '12 - 11:50 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #14 on: 28 Jun '12 - 07:05 »
Step by step: Set Progress Level meter.

Add ProgressBar1 and ProgressBar2 on the form.

Code: [Select]
Public Class Form1
    Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer
    Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer
    Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer
    Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer

    Public Function HiWord(ByRef lparam As Integer) As Integer
        HiWord = lparam \ &H10000 And &HFFFF
    End Function
    Public Function LoWord(ByRef lparam As Integer) As Integer
        LoWord = lparam And &HFFFF
    End Function

    Public strm As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        TrackBar1.TickStyle = TickStyle.None
        Button1.Text = "Open"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case Button1.Text
            Case "Open"
                Dim fileDLG As New OpenFileDialog()
                With fileDLG
                    .FileName = ""
                    .Filter = "Song file(*.mp3)|*.mp3"
                End With
                If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32)
                    BASS_ChannelStart()
                    strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0)
                    Button1.Text = "Play"
                End If
            Case "Play"
                If strm <> 0 Then
                    BASS_ChannelPlay(strm, 0, 0)
                    Button1.Text = "Stop"
                    Timer1.Enabled = True
                    TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm))
                End If
            Case "Stop"
                If strm <> 0 Then
                    BASS_ChannelStop(strm)
                    Button1.Text = "Open"
                    Timer1.Enabled = False
                    ProgressBar1.Value = 0
                    ProgressBar2.Value = 0
                    TrackBar1.Value = 0
                End If
        End Select
    End Sub

   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim sLen As Long = BASS_ChannelGetLength(strm)
        Dim sPos As Long = BASS_ChannelGetPosition(strm)
        Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen)
        Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos)
        TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm))
        If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0)
        Dim levels As Integer = BASS_ChannelGetLevel(strm)
        Dim RightChLvl As Integer = LoWord(levels)
        Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0)
        Dim LeftChLvl As Integer = HiWord(levels)
        Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0)
        Try
            ProgressBar1.Value = rightChLvlper
            ProgressBar2.Value = leftChLvlper
            Timer1.Interval = 50
        Catch
        End Try
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value))
    End Sub
End Class
« Last Edit: 28 Jun '12 - 08:30 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #15 on: 28 Jun '12 - 08:34 »
Step by step: Set sound timer.

Add Label1 and Label2 on the form.

Code: [Select]
Public Class Form1
    Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer
    Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer
    Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer
    Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer

    Public Function HiWord(ByRef lparam As Integer) As Integer
        HiWord = lparam \ &H10000 And &HFFFF
    End Function
    Public Function LoWord(ByRef lparam As Integer) As Integer
        LoWord = lparam And &HFFFF
    End Function

    Public Function TimeCalculation(ByVal intSecond As Integer) As String
        Dim v_i As Integer
        Dim v_i1 As Integer
        Dim v_str As String
        Dim v_str1 As String
        Dim v_arrstr As String()
        v_i = intSecond / 3600
        v_i1 = intSecond / 60
        v_i1 = v_i1 Mod 60
        intSecond = intSecond Mod 60
        v_arrstr = New String(4) {}
        v_arrstr(0) = v_i.ToString("00")
        v_arrstr(1) = ":"
        v_arrstr(2) = v_i1.ToString("00")
        v_arrstr(3) = ":"
        v_arrstr(4) = intSecond.ToString("00")
        v_str = String.Concat(v_arrstr)
        v_str1 = v_str
        Return v_str1
    End Function

    Public strm As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        Label1.Text = "00:00:00"
        Label2.Text = "00:00:00"
        Label1.BackColor = Color.White
        Label2.BackColor = Color.White
        Label1.BorderStyle = BorderStyle.Fixed3D
        Label2.BorderStyle = BorderStyle.Fixed3D
        TrackBar1.TickStyle = TickStyle.None
        Button1.Text = "Open"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case Button1.Text
            Case "Open"
                Dim fileDLG As New OpenFileDialog()
                With fileDLG
                    .FileName = ""
                    .Filter = "Song file(*.mp3)|*.mp3"
                End With
                If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32)
                    BASS_ChannelStart()
                    strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0)
                    Button1.Text = "Play"
                End If
            Case "Play"
                If strm <> 0 Then
                    BASS_ChannelPlay(strm, 0, 0)
                    Button1.Text = "Stop"
                    Timer1.Enabled = True
                    TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm))
                End If
            Case "Stop"
                If strm <> 0 Then
                    BASS_ChannelStop(strm)
                    Button1.Text = "Open"
                    Timer1.Enabled = False
                    ProgressBar1.Value = 0
                    ProgressBar2.Value = 0
                    TrackBar1.Value = 0
                End If
        End Select
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim sLen As Long = BASS_ChannelGetLength(strm)
        Dim sPos As Long = BASS_ChannelGetPosition(strm)
        Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen)
        Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos)
        TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm))
        If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0)
        Label1.Text = TimeCalculation(cPos)
        Label2.Text = TimeCalculation(cLen)
        Dim levels As Integer = BASS_ChannelGetLevel(strm)
        Dim RightChLvl As Integer = LoWord(levels)
        Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0)
        Dim LeftChLvl As Integer = HiWord(levels)
        Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0)
        Try
            ProgressBar1.Value = rightChLvlper
            ProgressBar2.Value = leftChLvlper
            Timer1.Interval = 50
        Catch
        End Try
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value))
    End Sub
End Class
« Last Edit: 28 Jun '12 - 09:47 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #16 on: 28 Jun '12 - 10:02 »
Step by step: Set sound volume

Add TrackBar2 on the form.

Code: [Select]
Public Class Form1
    Declare Function BASS_ChannelInit Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As Integer) As Integer
    Declare Function BASS_ChannelStart Lib "bass.dll" Alias "BASS_Start" () As Integer
    Declare Function BASS_ChannelCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Integer, ByVal file As String, ByVal offset As Integer, ByVal Length As Integer, ByVal streamflags As Integer) As Integer
    Declare Function BASS_ChannelPlay Lib "bass.dll" Alias "BASS_StreamPlay" (ByVal handle As Integer, ByVal flush As Integer, ByVal playflags As Integer) As Integer
    Declare Function BASS_ChannelStop Lib "bass.dll" Alias "BASS_Stop" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Single
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Single) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelGetLength Lib "bass.dll" Alias "BASS_StreamGetLength" (ByVal handle As Integer) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Integer
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
    Declare Function BASS_GetVolume Lib "bass.dll" () As Integer
    Declare Function BASS_SetVolume Lib "bass.dll" (ByVal volume As Integer) As Integer

    Public Function HiWord(ByRef lparam As Integer) As Integer
        HiWord = lparam \ &H10000 And &HFFFF
    End Function
    Public Function LoWord(ByRef lparam As Integer) As Integer
        LoWord = lparam And &HFFFF
    End Function

    Public Function TimeCalculation(ByVal intSecond As Integer) As String
        Dim v_i As Integer
        Dim v_i1 As Integer
        Dim v_str As String
        Dim v_str1 As String
        Dim v_arrstr As String()
        v_i = intSecond / 3600
        v_i1 = intSecond / 60
        v_i1 = v_i1 Mod 60
        intSecond = intSecond Mod 60
        v_arrstr = New String(4) {}
        v_arrstr(0) = v_i.ToString("00")
        v_arrstr(1) = ":"
        v_arrstr(2) = v_i1.ToString("00")
        v_arrstr(3) = ":"
        v_arrstr(4) = intSecond.ToString("00")
        v_str = String.Concat(v_arrstr)
        v_str1 = v_str
        Return v_str1
    End Function

    Public strm As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
        BASS_ChannelInit(-1, 44100, 0, Me.Handle.ToInt32)
        BASS_GetVolume()
        Label1.Text = "00:00:00"
        Label2.Text = "00:00:00"
        Label1.BackColor = Color.White
        Label2.BackColor = Color.White
        Label1.BorderStyle = BorderStyle.Fixed3D
        Label2.BorderStyle = BorderStyle.Fixed3D
        TrackBar1.TickStyle = TickStyle.None
        TrackBar2.Maximum = 100
        TrackBar2.Value = 100
        TrackBar2.TickStyle = TickStyle.Both
        Button1.Text = "Open"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case Button1.Text
            Case "Open"
                Dim fileDLG As New OpenFileDialog()
                With fileDLG
                    .FileName = ""
                    .Filter = "Song file(*.mp3)|*.mp3"
                End With
                If fileDLG.ShowDialog = Windows.Forms.DialogResult.OK Then
                    BASS_ChannelStart()
                    strm = BASS_ChannelCreateFile(0, fileDLG.FileName, 0, 0, 0)
                    Button1.Text = "Play"
                End If
            Case "Play"
                If strm <> 0 Then
                    BASS_ChannelPlay(strm, 0, 0)
                    Button1.Text = "Stop"
                    Timer1.Enabled = True
                    TrackBar1.Maximum = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetLength(strm))
                End If
            Case "Stop"
                If strm <> 0 Then
                    BASS_ChannelStop(strm)
                    Button1.Text = "Open"
                    Timer1.Enabled = False
                    ProgressBar1.Value = 0
                    ProgressBar2.Value = 0
                    TrackBar1.Value = 0
                    Label1.Text = "00:00:00"
                    Label2.Text = "00:00:00"
                End If
        End Select
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim sLen As Long = BASS_ChannelGetLength(strm)
        Dim sPos As Long = BASS_ChannelGetPosition(strm)
        Dim cLen As Single = BASS_ChannelBytes2Seconds(strm, sLen)
        Dim cPos As Single = BASS_ChannelBytes2Seconds(strm, sPos)
        TrackBar1.Value = BASS_ChannelBytes2Seconds(strm, BASS_ChannelGetPosition(strm))
        If cPos = cLen Then BASS_ChannelPlay(strm, 0, 0)
        Label1.Text = TimeCalculation(cPos)
        Label2.Text = TimeCalculation(cLen)
        Dim levels As Integer = BASS_ChannelGetLevel(strm)
        Dim RightChLvl As Integer = LoWord(levels)
        Dim rightChLvlper As Double = Math.Round((RightChLvl / 32768) * 25000, 0)
        Dim LeftChLvl As Integer = HiWord(levels)
        Dim leftChLvlper As Double = Math.Round((LeftChLvl / 32768) * 25000, 0)
        Try
            ProgressBar1.Value = rightChLvlper
            ProgressBar2.Value = leftChLvlper
            Timer1.Interval = 50
        Catch
        End Try
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        BASS_ChannelSetPosition(strm, BASS_ChannelSeconds2Bytes(strm, TrackBar1.Value))
    End Sub

    Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        BASS_SetVolume(TrackBar2.Value)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If strm <> 0 Then
            TrackBar2.Value = 0
            BASS_ChannelStop(strm)
        Else
            BASS_ChannelStop(strm)
        End If
    End Sub
End Class
« Last Edit: 28 Jun '12 - 11:06 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #17 on: 30 Jun '12 - 07:55 »
Download: Get start DirectBass (Un4Seen) basic programming Click here


« Last Edit: 30 Jun '12 - 08:00 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #18 on: 30 Jun '12 - 08:17 »
Imports System.Runtime.InteropServices

Add this code on ClassForm1 without Bass Module

Code: [Select]
Public strm As Integer
    Public Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr) As Boolean
        Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero)
    End Function
    <DllImport("bass.dll", SetLastError:=False)> _
    Private Shared Function BASS_Init(ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean
    End Function
    Public Function BASS_StreamCreateFile(ByVal [file] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
        flags = flags Or BASSFlag.BASS_UNICODE
        Return BASS_StreamCreateFileUnicode(False, [file], offset, length, flags)
    End Function
    <DllImport("bass.dll", EntryPoint:="BASS_StreamCreateFile", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.[Auto], SetLastError:=False)> _
    Private Shared Function BASS_StreamCreateFileUnicode(<MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal A_0 As Boolean, <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
    <DllImport("bass.dll")> _
    Public Shared Function BASS_StreamFree(ByVal A_0 As Integer) As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelPlay(ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelPause(ByVal A_0 As Integer) As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelStop(ByVal handle As Integer) As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_Start() As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_Stop() As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetLevel(ByVal handle As Integer) As Integer
    End Function
    <DllImport("bass.dll", SetLastError:=False)> _
    Public Shared Function BASS_ChannelGetData(ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelSeconds2Bytes(ByVal handle As Integer, ByVal pos As Double) As Long
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelBytes2Seconds(ByVal handle As Integer, ByVal pos As Long) As Double
    End Function
    Public Function BASS_ChannelGetLength(ByVal handle As Integer) As Long
        Return BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTES)
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetLength(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function
    Public Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long
        Return BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES)
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelGetPosition(ByVal handle As Integer, ByVal mode As BASSMode) As Long
    End Function
    Public Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Boolean
        Return BASS_ChannelSetPosition(handle, pos, BASSMode.BASS_POS_BYTES)
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_ChannelSetPosition(ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_GetVolume() As Single
    End Function
    <DllImport("bass.dll")> _
    Public Shared Function BASS_SetVolume(ByVal A_0 As Single) As Boolean
    End Function
    Public Function FixTimespan(ByVal seconds As Double) As String
        Dim v_timeSpan As System.TimeSpan
        v_timeSpan = System.TimeSpan.FromSeconds(seconds)
        Return v_timeSpan.ToString
    End Function
    Public Function HighWord(ByVal dWord As Integer) As Short
        Return CShort((dWord >> 16) And 65535)
    End Function
    Public Function HighWord(ByVal qWord As Long) As Integer
        Return CInt((qWord >> 32) And -1)
    End Function
    Public Function HighWord32(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function
    Public Function LowWord(ByVal dWord As Integer) As Short
        Return CShort(dWord And 65535)
    End Function
    Public Function LowWord(ByVal qWord As Long) As Integer
        Return CInt(qWord And -1)
    End Function
    Public Function LowWord32(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function
    Public Function BASS_ChannelGetLevel(ByVal handle As Integer, ByVal level As Single()) As Boolean
        Dim v_i As Integer
        Dim v_arrsng As Single()
        Dim v_i1 As Integer
        Dim v_sng As Single
        Dim v_i2 As Integer
        If level.Length <= 0 Then
            GoTo ILO_0012
        End If
        System.Array.Clear(level, 0, level.Length)
        GoTo ILO_0014
ILO_0012:
        Return False
ILO_0014:
        v_i = CInt(BASS_ChannelSeconds2Bytes(handle, 0.02))
        If v_i <= 0 Then
            GoTo ILO_0079
        End If
        v_arrsng = New Single((v_i / 4) - 1) {}
        v_i = BASS_ChannelGetData(handle, v_arrsng, v_i Or 1073741824)
        v_i /= 4
        v_i1 = 0
        v_i2 = 0
        GoTo ILO_0072
ILO_004c:
        v_sng = System.Math.Abs(v_arrsng(v_i2))
        If v_sng <= level(v_i1) Then
            GoTo ILO_0060
        End If
        level(v_i1) = v_sng
ILO_0060:
        v_i1 += 1
        If v_i1 < level.Length Then
            GoTo ILO_006c
        End If
        v_i1 = 0
ILO_006c:
        v_i2 += 1
ILO_0072:
        If v_i2 < v_i Then
            GoTo ILO_004c
        End If
        Return True
ILO_0079:
        Return False
    End Function
    <Flags()> _
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_SAMPLE_FLOAT = 256
        BASS_STREAM_PRESCAN = 131072
        BASS_STREAM_AUTOFREE = 262144
        BASS_STREAM_STATUS = 8388608
        BASS_UNICODE = -2147483648
        BASS_MUSIC_MONO = 2
        BASS_MUSIC_LOOP = 4
        BASS_MUSIC_3D = 8
        BASS_MUSIC_FX = 128
        BASS_MUSIC_AUTOFREE = 262144
        BASS_MUSIC_PRESCAN = 131072
        BASS_MUSIC_POSRESET = 32768
    End Enum
    <Flags()> _
    Public Enum BASSInit
        BASS_DEVICE_DEFAULT = 0
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS = 2048
        BASS_DEVICE_NOSPEAKER = 4096
        BASS_DEVICE_FREQ = 16384
    End Enum
    <Flags()> _
    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
    End Enum

Bass form design. Use ImageList set Image all Buttons to use

Writting code Sub New InitializeComponent

Add code Create ImageList and Form Object Properties Without Form Load.
 
Code: [Select]
Public Sub New()
        InitializeComponent()
        '-------------------- Form Object properties ---------------------
        Me.CenterToScreen()
        Me.Text = "Bass Un4Seen Sample"
        Me.MaximizeBox = False
        Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
        BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
        Label1.Text = "SongName:"
        Label2.Text = "00:00:00"
        Label3.Text = "00:00:00"
        Label4.Text = "0%"
        TrackBar1.TickStyle = TickStyle.None
        Button1.Text = ""
        Button2.Text = ""
        Button3.Text = ""
        Button4.Text = ""
        BASS_GetVolume()
        ProgressBar1.Maximum = 100
        ProgressBar2.Maximum = 100
        TrackBar2.Maximum = 100
        TrackBar2.Value = 100
        '-------------------------------- ImageList Create ----------------------------
        Dim ImageList1 As New ImageList()
        ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnOpen.ico"))
        Button1.ImageList = ImageList1
        Button1.ImageIndex = 0
        ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnPlay.ico"))
        Button2.ImageList = ImageList1
        Button2.ImageIndex = 1
        ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnPause.ico"))
        Button3.ImageList = ImageList1
        Button3.ImageIndex = 2
        ImageList1.Images.Add(Image.FromFile("C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Icons\icnStop.ico"))
        Button4.ImageList = ImageList1
        Button4.ImageIndex = 3
    End Sub


« Last Edit: 1 Jul '12 - 12:06 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #19 on: 2 Jul '12 - 10:29 »
Get DirectBass(Un4Seen) Lib Function Command

Code: [Select]
Public Class Form1
    Declare Function BASS_Init Lib "bass.dll" (ByVal A_0 As Integer, ByVal A_1 As Integer, ByVal A_2 As BASSInit, ByVal A_3 As System.IntPtr, ByVal A_4 As System.IntPtr) As Boolean
    Declare Function BASS_StreamCreateFileUnicode Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal A_0 As Boolean, <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
    Declare Function BASS_StreamFree Lib "bass.dll" (ByVal A_0 As Integer) As Boolean
    Declare Function BASS_ChannelPlay Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Boolean) As Boolean
    Declare Function BASS_ChannelPause Lib "bass.dll" (ByVal A_0 As Integer) As Boolean
    Declare Function BASS_ChannelStop Lib "bass.dll" (ByVal handle As Integer) As Boolean
    Declare Function BASS_Start Lib "bass.dll" () As Boolean
    Declare Function BASS_Stop Lib "bass.dll" () As Boolean
    Declare Function BASS_ChannelGetLevel Lib "bass.dll" (ByVal handle As Integer) As Integer
    Declare Function BASS_ChannelGetData Lib "bass.dll" (ByVal handle As Integer, ByVal buffer As Single(), ByVal length As Integer) As Integer
    Declare Function BASS_ChannelSeconds2Bytes Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Double) As Long
    Declare Function BASS_ChannelBytes2Seconds Lib "bass.dll" (ByVal handle As Integer, ByVal pos As Long) As Double
    Declare Function BASS_ChannelGetLength Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long
    Declare Function BASS_ChannelGetPosition Lib "bass.dll" (ByVal handle As Integer, ByVal mode As BASSMode) As Long
    Declare Function BASS_ChannelSetPosition Lib "bass.dll" (ByVal A_0 As Integer, ByVal handle As Long, ByVal pos As BASSMode) As Boolean
    Declare Function BASS_GetVolume Lib "bass.dll" () As Single
    Declare Function BASS_SetVolume Lib "bass.dll" (ByVal A_0 As Single) As Boolean
    Public strm As Integer
    Public Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As System.IntPtr) As Boolean
        Return BASS_Init(device, freq, flags, win, System.IntPtr.Zero)
    End Function
    Public Function BASS_StreamCreateFile(ByVal [File] As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
        flags = flags Or BASSFlag.BASS_UNICODE
        Return BASS_StreamCreateFileUnicode(False, [File], offset, length, flags)
    End Function
    Public Function BASS_ChannelGetLength(ByVal handle As Integer) As Long
        Return BASS_ChannelGetLength(handle, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function BASS_ChannelGetPosition(ByVal handle As Integer) As Long
        Return BASS_ChannelGetPosition(handle, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function BASS_ChannelSetPosition(ByVal handle As Integer, ByVal pos As Long) As Boolean
        Return BASS_ChannelSetPosition(handle, pos, BASSMode.BASS_POS_BYTES)
    End Function
    Public Function FixTimespan(ByVal seconds As Double) As String
        Dim v_timeSpan As System.TimeSpan
        v_timeSpan = System.TimeSpan.FromSeconds(seconds)
        Return v_timeSpan.ToString
    End Function
    Public Function HighWord32(ByVal dWord As Integer) As Integer
        Return (dWord >> 16) And 65535
    End Function
    Public Function LowWord32(ByVal dWord As Integer) As Integer
        Return dWord And 65535
    End Function
    <Flags()> _
    Public Enum BASSFlag
        BASS_DEFAULT = 0
        BASS_SAMPLE_FLOAT = 256
        BASS_STREAM_PRESCAN = 131072
        BASS_STREAM_AUTOFREE = 262144
        BASS_STREAM_STATUS = 8388608
        BASS_UNICODE = -2147483648
        BASS_MUSIC_LOOP = 4
        BASS_MUSIC_AUTOFREE = 262144
        BASS_MUSIC_PRESCAN = 131072
        BASS_MUSIC_POSRESET = 32768
    End Enum
    <Flags()> _
    Public Enum BASSInit
        BASS_DEVICE_DEFAULT = 0
        BASS_DEVICE_CPSPEAKERS = 1024
        BASS_DEVICE_SPEAKERS = 2048
        BASS_DEVICE_NOSPEAKER = 4096
        BASS_DEVICE_FREQ = 16384
    End Enum
    <Flags()> _
    Public Enum BASSMode
        BASS_POS_BYTES = 0
        BASS_POS_MUSIC_ORDERS = 1
        BASS_MUSIC_POSRESET = 32768
        BASS_MUSIC_POSRESETEX = 4194304
    End Enum
End Class
« Last Edit: 3 Jul '12 - 21:54 by sak2005 »

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #20 on: 3 Jul '12 - 08:35 »
Tip: Winmm 'mciSendString' MediaControl Lib Function

Browse lib file MediaControl.dll from MyPlayer_vb sample project add to referents of new project at create.

Add buttons. For open, play and stop) on the form.

Writting code now.

Example:
Code: [Select]
Public Class Form1
    Private media As New MediaControl.AudioPlayer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fdlg As New OpenFileDialog
        fdlg.FileName = ""
        fdlg.Filter = "Song file(*.mp3)|*.mp3"
        If fdlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            media.Close()
            media.Open(fdlg.FileName)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        media.Play()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        media.Stop()
    End Sub

    Public Sub New()
        InitializeComponent()
        Me.CenterToScreen()
        Button1.Text = "Open"
        Button2.Text = "Play"
        Button3.Text = "Stop"
    End Sub
End Class
============================================================
Sample2: Out of Referents

If not referents dll file. You must add dll file in to a debug folder of new project. And writting function code on Class.

Get start : Add new buttons is Button1, Button2 and Button3 on the form.
               Add new labels is Label1, Label2, Label3 and Label4 on the form.
               Add TrackBar1 and TrackBar2 on the form.
               Add ToolTip and Timer1 on the form.
Writting code now...

Code: [Select]
Public Class Form1
    'Call soundMedia DLLs
    Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal strCommand As String, ByVal strReturn As System.Text.StringBuilder, ByVal iReturnLength As Integer, ByVal hwndCallback As System.IntPtr) As Long
    Public Sub New()
        MyBase.New()
        InitializeComponent()
        fgProperties()
    End Sub
    '----------------------- Function mciMedia Control ----------------------------------------------------------
    Dim fdlg As OpenFileDialog = New OpenFileDialog()
    Public Sub SoundOpen()
        fdlg.FileName = ""
        fdlg.Filter = "Mpeg file(*.mp3)|*.mp3"
        If fdlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            SoundClose()
            Dim strCommand As String = String.Concat("open """, fdlg.FileName, """ type mpegvideo alias mpegfile")
            mciSendString(strCommand, Nothing, 0, IntPtr.Zero)
            Dim lBuff = New System.Text.StringBuilder(128)
            Dim lCommand As String = "status mpegfile length"
            mciSendString(lCommand, lBuff, lBuff.Capacity, IntPtr.Zero)
            Label4.Text = FileIO.FileSystem.GetName(fdlg.FileName)
        End If
    End Sub
    Public Sub SoundPlay()
        If Timer1.Enabled = True Then Timer1.Enabled = False
        If fdlg.FileName <> "" Then
            Dim strCommand As String = "play mpegfile"
            mciSendString(strCommand, Nothing, 0, IntPtr.Zero)
            ResPos()
            Timer1.Enabled = True
        End If
    End Sub
    Public Sub SoundStop()
        Dim strCommand As String = "stop mpegfile"
        ResPos()
        mciSendString(strCommand, Nothing, 0, IntPtr.Zero)
        If fdlg.FileName <> "" Then
            ResTextPos()
        End If
        Timer1.Enabled = False
    End Sub
    Public Sub SoundClose()
        Dim strCommand As String = "close mpegfile"
        mciSendString(strCommand, Nothing, 0, IntPtr.Zero)
    End Sub
    Public Sub ResTextPos()
        Dim Zero As Integer = 0
        Label2.Text = TimeSpan.Zero.ToString
        Label3.Text = Zero.ToString & "%"
        TrackBar1.Value = TrackBar1.Minimum
    End Sub
    Public Sub ResPos()
        Dim FstrCommand As String = String.Concat("play mpegfile from ", 0)
        mciSendString(FstrCommand, Nothing, 0, System.IntPtr.Zero)
    End Sub
    '-------------------------- Object Event Control -------------------------------------------------------------
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SoundOpen()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SoundPlay()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        SoundStop()
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        tbScrollPos(TrackBar1.Value)
        ToolTip1.SetToolTip(TrackBar1, TrackBar1.Value * 100 / 100)
    End Sub
    Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        mciSendString(String.Concat("setaudio mpegfile volume to ", TrackBar2.Value * 1000 / 100), Nothing, 0, System.IntPtr.Zero)
        ToolTip1.SetToolTip(TrackBar2, TrackBar2.Value * 100 / 100)
    End Sub
    Private Sub TrackBar1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.MouseLeave
        ToolTip1.SetToolTip(TrackBar1, "")
    End Sub
    Private Sub TrackBar2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.MouseLeave
        ToolTip1.SetToolTip(TrackBar2, "")
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        SoundClose()
    End Sub
    Dim percent As Integer
    Dim LstrBuffer = New System.Text.StringBuilder(128)
    Dim PstrBuffer = New System.Text.StringBuilder(128)
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim sCommand As String = "status mpegfile position"
        Dim lCommand As String = "status mpegfile length"
        mciSendString(lCommand, LstrBuffer, LstrBuffer.Capacity, System.IntPtr.Zero)
        mciSendString(sCommand, PstrBuffer, PstrBuffer.Capacity, IntPtr.Zero)
        percent = Math.Round((PstrBuffer.ToString / LstrBuffer.ToString) * 100, 0)
        Label1.Text = CalcTimes(LstrBuffer.ToString)
        Label2.Text = CalcTimes(PstrBuffer.ToString)
        Label3.Text = tbPercentValue() & "%"
        TrackBar1.Value = tbPercentValue()
        If tbPercentValue() >= 100 And Label2.Text >= Label1.Text Then
            SoundStop()
            ResTextPos()
            Timer1.Enabled = False
        End If
    End Sub
    '---------Set Form Object Properties ---------
    Public Sub fgProperties()
        Me.Text = "Sound Player Sample"
        Me.CenterToScreen()
        Label1.Text = ""
        Label2.Text = ""
        Label3.Text = ""
        Label4.Text = ""
        Button1.Text = "Open"
        Button2.Text = "Play"
        Button3.Text = "Stop"
        TrackBar1.TickStyle = TickStyle.None
        TrackBar1.Maximum = 100
        TrackBar2.TickStyle = TickStyle.Both
        TrackBar2.Maximum = 100
        TrackBar2.Value = TrackBar2.Maximum
    End Sub
    '---------------------------Set Scroll Position --------------------------------------
    Public Function tbScrollPos(ByVal tbValue As Integer) As Integer
        If fdlg.FileName <> "" Then
            Dim lBuff = New System.Text.StringBuilder(128)
            Dim lCommand As String = "status mpegfile length"
            mciSendString(lCommand, lBuff, lBuff.Capacity, IntPtr.Zero)
            Dim iLength As Integer = Math.Round(lBuff.ToString / 100)
            Dim fCommand As String = String.Concat("play mpegfile from ", tbValue.ToString * iLength.ToString)
            mciSendString(fCommand, Nothing, 0, System.IntPtr.Zero)
            If percent >= 100 Then
                TrackBar1.Value = 0
                Timer1.Enabled = True
            Else
                Timer1.Enabled = True
            End If
        End If
    End Function
    '-------------------------- Set TimeSpan ----------------------------
    Public Function CalcTimes(ByVal milliseconds As Double) As String
        Dim VtimeSpan As System.TimeSpan
        VtimeSpan = System.TimeSpan.FromMilliseconds(milliseconds)
        Return Strings.Left(VtimeSpan.ToString, 8)
    End Function
    '----------------------- Set PercentValuePosition ---------------------
    Public Function tbPercentValue() As Integer
        Return Math.Round((PstrBuffer.ToString / LstrBuffer.ToString) * 100)
    End Function
End Class
« Last Edit: 7 Jul '12 - 08:08 by sak2005 »

skygamer

  • Posts: 3
Re: Direct bass : Vb.net
« Reply #21 on: 5 Jul '12 - 07:09 »
thats amazing.  ;D  thank you.

But i need 10 bands equalizer. How can i implement it? I've searched but nothing found for vb.net

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #22 on: 5 Jul '12 - 12:35 »
thats amazing.  ;D  thank you.

But i need 10 bands equalizer. How can i implement it? I've searched but nothing found for vb.net

Yes, It's not has in the internet. You must modify convert from C# to VB.net.

sak2005

  • Posts: 1007
Re: Direct bass : Vb.net
« Reply #23 on: 9 Jul '12 - 00:55 »
Tip!: Create Timer Event Handler on the Class

Add ProgressBar1 , Label1 and Button1 on the form. Writting code now.

Code: [Select]
Public Class Form1
    'create new timer
    Private time As New Timer()

    'call form design
    Public Sub New()
        InitializeComponent()
        Me.CenterToScreen()
        Button1.Text = "Start"
        Label1.Text = "0% Completed"

        'create add event handle
        AddHandler time.Tick, AddressOf Progress_tick
        time.Interval = 250
    End Sub

   'create event timer tick function
    Public Sub Progress_tick(ByVal sender As Object, ByVal e As EventArgs)
        Dim rand As New Random
        ProgressBar1.Increment(rand.Next(0, 10))
        Label1.Text = ProgressBar1.Value.ToString() + "% Completed"
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            time.Stop()
            MsgBox("100% Completed")
            ProgressBar1.Value = ProgressBar1.Minimum
            Label1.Text = "0% Completed"
        End If
    End Sub

    'start timer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        time.Start()
    End Sub
End Class
================================================================
Tip: EventClass EventHandler

Create Form1 and add Button1. Writting code now.

Example:
Code: [Select]
Public Class Form1

    '2.Call and Create New EventClass.
    Dim WithEvents Eclass As New EventClass

    '3.Create EventHandle Function.(get to send)
    Sub Eclass_EventHandler() Handles Eclass.Aevent
        MsgBox("Received Event.")
    End Sub

    '4.EventClass Test.(send to EventHandler)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Eclass.RaiseEvents()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
    End Sub
End Class

'1.Create EventClass..RaiseEvent.
Class EventClass
    Public Event Aevent()
    Sub RaiseEvents()
        RaiseEvent Aevent()
    End Sub
End Class
« Last Edit: 11 Jul '12 - 16:58 by sak2005 »

dregalia

  • Posts: 10
Re: Direct bass : Vb.net
« Reply #24 on: 9 Jul '12 - 06:19 »
Hey brotha, Loving the VB.NET stuff.. Do you have an example that I can use to play one song after another?