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

sak2005

  • Posts: 972
Tip: Reverse sound volume for Dshow , From.. min = -4000 , max = 0 To min = 0  and max = 4000

Example:
Code: [Select]
Private r As Integer

    Public Overridable Sub VolumeReverses(ByVal max As Integer, ByVal vol As Integer)
        On Error Resume Next
        If max = 10 Or max = 100 Or max = 4000 Then
            Dim s As Integer = CInt(vol - max)
            r = s
            If max = 100 Then
                Volume(r * 40) 'method to used.
            ElseIf max = 10 Then
                Volume(r * 400)
            Else
                If max = 4000 Then
                    Volume(r)
                End If
            End If
        Else
            MsgBox("Error! Must set maxValue volume = 10, 100 or 4000")
        End If
    End Sub

    ''' <summary>
    ''' using method is VolumeReverseValue() function set is Value.
    ''' </summary>
    ''' <param name="max"></param>
    ''' <param name="vol"></param>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overridable Property VolumeReverse(ByVal max As Integer, ByVal vol As Integer) As Integer
        Get
            Return r
        End Get
        Set(ByVal value As Integer)
            r = value
            On Error Resume Next
            If max = 10 Or max = 100 Or max = 4000 Then
                Dim s As Integer = CInt(vol - max)
                r = s
                If max = 100 Then
                    Volume(r * 40) 'method to used.
                ElseIf max = 10 Then
                    Volume(r * 400)
                Else
                    If max = 4000 Then
                        Volume(r)
                    End If
                End If
            Else
                MsgBox("Error! Must set maxValue volume = 10, 100 or 4000")
            End If
        End Set
    End Property

    Public Overridable Function VolumeReverseValue() As Integer
        Return r
    End Function

    Public Overridable Sub Balance(ByVal max As Integer, ByVal bal As Integer)
        Select Case max
            Case 10
                soundBuffer.Pan = bal * 400
            Case 100
                soundBuffer.Pan = bal * 40
            Case 4000
                soundBuffer.Pan = bal 'method to used.
            Case Else
                MsgBox("Error! Must set max value = 10, 100 or 4000")
        End Select
    End Sub

sak2005

  • Posts: 972
Tip: How to using directshow in the WindowsMedia.dll ::)

Example:
Code: [Select]
Imports WindowsApplication2.DirectShow
Public Class Form1
    Private ds As New DirectShow
    Private fd As New OpenFileDialog
    Private btn As New Button
    Private WithEvents ptb As New TrackBar
    Private WithEvents vtb As New TrackBar
    Private WithEvents btb As New TrackBar
    Private lbl, slbl As New Label
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        btn.Text = "Open"
        vtb.Maximum = 100
        vtb.Value = vtb.Maximum
        vtb.TickFrequency = CInt(vtb.Maximum / 100 * 10)
        btb.Minimum = -100
        btb.Maximum = 100
        btb.Value = 0
        btb.TickFrequency = CInt(btb.Maximum / 100 * 10)
        Controls.AddRange(New Control() {btn, vtb, ptb, btb, slbl, lbl})
        ptb.Location = New Point(85, 0)
        vtb.Location = New Point(0, 50)
        btb.Location = New Point(185, 50)
        lbl.Text = "00:00:00/00:00:00"
        lbl.Location = New Point(195, 0)
        slbl.Text = "Stopped"
        slbl.Location = New Point(120, 100)
        AddHandler btn.Click, AddressOf btn_Click
        AddHandler ds.PositionChanged, AddressOf ds_PositionChanged
    End Sub
    Private Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
        Select Case btn.Text
            Case "Open"
                If fd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    ds.Open(fd.FileName)
                    ptb.Maximum = ds.maxPosition
                    lbl.Text = TimeSpan.FromSeconds(CDbl(ptb.Maximum)).ToString.Substring(0, 8)

                    ds.Play()
                    btn.Text = "Stop"
                End If
            Case "Stop"
                ds.Pause()
                Dim Result As MsgBoxResult = MsgBox("Do you wanted to Playing?", MsgBoxStyle.Question Or MsgBoxStyle.YesNoCancel, "")
                Select Case Result
                    Case MsgBoxResult.Yes
                        btn.Text = "Play"
                    Case MsgBoxResult.No
                        ds.Stop()
                        btn.Text = "Open"
                    Case MsgBoxResult.Cancel
                        GoTo LIO
                    Case Else
                        Exit Select
                End Select
            Case "Play"
LIO:
                ds.Play()
                btn.Text = "Stop"
        End Select
    End Sub
    Private Sub ds_PositionChanged(ByVal e As WindowsApplication2.PositionChangedEventArgs)
        ptb.Value = e.CurrentPos
        lbl.Text = TimeSpan.FromSeconds(CDbl(ptb.Value)).ToString.Substring(0, 8) & "/" & TimeSpan.FromSeconds(CDbl(ptb.Maximum)).ToString.Substring(0, 8)
        slbl.Text = ds.Status
    End Sub
    Private Sub tb_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles ptb.Scroll
        ds.CurrentPosition = ptb.Value
    End Sub
    Private Sub vtb_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles vtb.Scroll, vtb.ValueChanged
        ds.VolumeReverse(vtb.Maximum, vtb.Value)
    End Sub
    Private Sub btb_Scroll(ByVal sender As Object, ByVal e As EventArgs) Handles btb.Scroll, btb.ValueChanged
        ds.Balance(btb.Maximum, btb.Value)
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        ds.Close()
    End Sub
End Class
'References Import WindowsMedia.dll
Public Class DirectShow
    Private gb As Ernzo.Windows.DirectShowLib.IGraphBuilder
    Private ba As Ernzo.Windows.DirectShowLib.IBasicAudio
    Private mf As Ernzo.Windows.DirectShowLib.IMediaFilter
    Private ms As Ernzo.Windows.DirectShowLib.IMediaSeeking
    Private stime As System.Threading.Thread
    Private len As Integer
    Private pos As Integer
    Private sfile As String
    Public Sub New()
        MyBase.New()
        Control.CheckForIllegalCrossThreadCalls = False
        Me.gb = Nothing
        Me.ba = Nothing
        Me.mf = Nothing
        Me.ms = Nothing
        Me.stime = Nothing
        Me.len = 0
        Me.pos = 0
        Me.sfile = String.Empty
    End Sub
    Protected Overrides Sub Finalize()
        ReleaseGraph()
        gb = Nothing
        MyBase.Finalize()
    End Sub
    Public Overridable Sub BuildGraph()
        gb = DirectCast(New Ernzo.Windows.DirectShowLib.FilterGraph, Ernzo.Windows.DirectShowLib.IFilterGraph)
        ba = DirectCast(gb, Ernzo.Windows.DirectShowLib.IBasicAudio)
        mf = DirectCast(gb, Ernzo.Windows.DirectShowLib.IMediaFilter)
        ms = DirectCast(gb, Ernzo.Windows.DirectShowLib.IMediaSeeking)
    End Sub
    Public Overridable Sub ReleaseGraph()
        If gb IsNot Nothing Then
            If Runtime.InteropServices.Marshal.IsComObject(gb) Then
                Runtime.InteropServices.Marshal.ReleaseComObject(gb)
            End If
        End If
    End Sub
    Public Overridable Sub StartTime()
        If stime Is Nothing Then
            stime = New Threading.Thread(New Threading.ThreadStart(AddressOf Me.OnPosTime))
            stime.Priority = Threading.ThreadPriority.Lowest
            stime.Start()
        End If
    End Sub
    Public Overridable Function Open(ByVal strFile As String) As Integer
        If sfile <> String.Empty Then
            ReleaseGraph()
        End If
        sfile = strFile
        BuildGraph()
        Return gb.RenderFile(sfile, Nothing)
    End Function
    Public Overridable Function Play() As Integer
        If mf IsNot Nothing Then
            StartTime()
            Return mf.Run(0)
        End If
    End Function
    Public Overridable Function Pause() As Integer
        If mf IsNot Nothing Then
            Return mf.Pause()
        End If
    End Function
    Public Overridable Function [Stop]() As Integer
        If mf IsNot Nothing Then
            SetPosition(0)
            Return mf.Stop()
        End If
    End Function
    Public Overridable Function Close() As Integer
        If stime IsNot Nothing Then
            stime.Abort()
            stime.Join()
            stime = Nothing
        End If
    End Function
    Public Overridable Function State() As Ernzo.Windows.DirectShowLib.FilterState
        If mf IsNot Nothing Then
            Dim st As Ernzo.Windows.DirectShowLib.FilterState
            mf.GetState(0, st)
            Return st
        End If
    End Function
    Public Overridable Function SetPosition(ByVal pos As Integer) As Integer
        If ms IsNot Nothing Then
            Dim pc As Long
            ms.GetCurrentPosition(pc)
            Dim p As Long = pc
            p = CLng(pos * 10000000)
            ms.SetPositions(p, Ernzo.Windows.DirectShowLib.AM_SEEKING_SeekingFlags.AM_SEEKING_AbsolutePositioning, 0, Ernzo.Windows.DirectShowLib.AM_SEEKING_SeekingFlags.AM_SEEKING_NoPositioning)
        End If
    End Function
    Public Sub VolumeReverse(ByVal vMax As Integer, ByVal vValue As Integer)
        If ba IsNot Nothing Then
            If vMax <> -4000 Then
                Dim lValue As Integer = CInt(vValue - vMax)
                Select Case vMax
                    Case 10
                        ba.put_Volume(CInt(lValue * 400))
                    Case 100
                        ba.put_Volume(CInt(lValue * 40))
                    Case Else
                        ba.put_Volume(lValue)
                End Select
            Else
                ba.put_Volume(vValue)
            End If
        End If
    End Sub
    Public Overridable Sub Balance(ByVal bMax As Integer, ByVal bBal As Integer)
        If ba IsNot Nothing Then
            Select Case bMax
                Case 10
                    ba.put_Balance(CInt(bBal * 400))
                Case 100
                    ba.put_Balance(CInt(bBal * 40))
                Case Else
                    ba.put_Balance(bBal)
            End Select
        End If
    End Sub
    Public Overridable ReadOnly Property Status() As String
        Get
            Return State().ToString.Substring(6)
        End Get
    End Property

    Public Overridable ReadOnly Property Duration() As Integer
        Get
            If ms IsNot Nothing Then
                Dim pd As Long
                ms.GetDuration(pd)
                len = CInt(pd / 10000000)
                Return len
            End If
        End Get
    End Property
    Public Overridable ReadOnly Property maxPosition() As Integer
        Get
            Return Duration()
        End Get
    End Property
    Public Overridable Property CurrentPosition() As Integer
        Get
            If ms IsNot Nothing Then
                Dim pc As Long
                ms.GetCurrentPosition(pc)
                pos = CInt(pc / 10000000)
                Return pos
            End If
        End Get
        Set(ByVal value As Integer)
            pos = value
            ms.SetPositions(CLng(pos * 10000000), Ernzo.Windows.DirectShowLib.AM_SEEKING_SeekingFlags.AM_SEEKING_AbsolutePositioning, 0, Ernzo.Windows.DirectShowLib.AM_SEEKING_SeekingFlags.AM_SEEKING_NoPositioning)
        End Set
    End Property

    Public Overridable Sub OnPositionChanged(ByVal e As PositionChangedEventArgs)
        If PositionChangedEvent IsNot Nothing Then
            RaiseEvent PositionChanged(e)
        End If
    End Sub
    Protected Overridable Sub OnPosTime()
        Do
            If CurrentPosition < Duration Then
                OnPositionChanged(New PositionChangedEventArgs(pos))
                Threading.Thread.Sleep(50)
            Else
                [Stop]()
            End If
            Application.DoEvents()
        Loop
    End Sub
    Public Event PositionChanged As PositionChangedEventHandler
End Class
Public Delegate Sub PositionChangedEventHandler(ByVal e As PositionChangedEventArgs)
Public Class PositionChangedEventArgs
    Inherits EventArgs
    Private pos As Integer
    Public Sub New()
        MyBase.New()
        Me.pos = 0
    End Sub
    Public Sub New(ByVal _pos As Integer)
        MyBase.New()
        Me.pos = _pos
    End Sub
    Public Overridable ReadOnly Property CurrentPos() As Integer
        Get
            Return Me.pos
        End Get
    End Property
End Class
« Last Edit: 1 Sep '17 - 14:54 by sak2005 »

sak2005

  • Posts: 972
Tip: Learn more about with Threading ::)

For example, Creatting BassPlayer Form Application, using PositionChanged EventHandler

1. Create ThreadStart function
2. Created OnMethod function
3. Created OnEvent function
4. Public Event
5. Public Delegate
6. Created EventArgs class

Example:
Code: [Select]
using System;
using System.Data;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace BassPlayerSample
{
    public partial class Form1 : Form
    {
        #region APIs
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_Init(int device, int freq, int flags, IntPtr win, IntPtr clsid);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_StreamFree(int handle);
        [DllImport("bass.dll", CharSet = CharSet.Auto, EntryPoint = "BASS_StreamCreateFile")]
        private static extern int BASS_StreamCreateFileUnicode(bool mem, string strfile, long offset, long length, int flags);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_ChannelPlay(int handle, bool restart);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_ChannelPause(int handle);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_ChannelStop(int handle);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_Free();
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern double BASS_ChannelBytes2Seconds(int handle, long lenpos);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern long BASS_ChannelGetLength(int handle, int mode);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern long BASS_ChannelGetPosition(int handle, int mode);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern long BASS_ChannelSeconds2Bytes(int handle, double pos);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern bool BASS_ChannelSetPosition(int handle, long pos, int mode);
        #endregion;
       
        #region contructors
        const int BASS_UNICODE = -2147483648;
        const int BASS_POS_BYTE = 0;
        OpenFileDialog ofd;
        Thread thread = null;
        double len;
        double pos;
        string sfile;
        int chan, strm;
        public Form1()
        {
            InitializeComponent();
            this.ofd = new OpenFileDialog();
            this.len = 0;
            this.pos = 0;
            this.sfile = string.Empty;
            this.chan = 0;
            this.PositionChanged +=new PositionChangedEventHandler(Form1_PositionChanged);
        }
        #endregion;
       
        #region methods
        public bool Bass_Init(int device, int freq, int flags, IntPtr win)
        {
            return BASS_Init(device, freq, flags, win, IntPtr.Zero);
        }
        public bool Bass_StreamFree(int handle)
        {
            return BASS_StreamFree(handle);
        }
        public int Bass_StreamCreateFile(string strfile, long offset, long length, int flags)
        {
            flags |= BASS_UNICODE;
            if (sfile != string.Empty) { Bass_StreamFree(chan); }
            sfile = strfile;
            chan = BASS_StreamCreateFileUnicode(false, sfile, offset, length, flags);
            if (chan == 0) { MessageBox.Show("Error! file not support."); return 0; }
            return chan;
        }
        public bool Bass_ChannelPlay(int handle, bool restart)
        {
            StartTimer();
            return BASS_ChannelPlay(handle, restart);
        }
        public bool Bass_ChannelPause(int handle)
        {
           return BASS_ChannelPause(handle);
        }
        public bool Bass_ChannelStop(int handle)
        {
            CurrentPosition = 0;
            return BASS_ChannelStop(handle);
        }
        public bool Bass_Close()
        {
            if (thread != null)
            {
                thread.Abort();
                thread.Join();
            }
            return BASS_Free();
        }
        public double Duration
        {
            get
            {
                len = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, BASS_POS_BYTE));
                return len;
            }
        }
        public double MaxPosition
        {
            get
            {
                return Duration;
            }
        }
        public double CurrentPosition
        {
            get
            {
                pos = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetPosition(chan, BASS_POS_BYTE));
                return pos;
            }
            set
            {
                pos = value;
                BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, pos), BASS_POS_BYTE);
            }
        }
        public void StartTimer()
        {
            if (thread == null)
            {
                thread = new Thread(new ThreadStart(OnTimer));
                thread.IsBackground = true; //debug close thread fail.
                thread.Priority = ThreadPriority.Normal;
                thread.Start();
            }
        }
        protected void OnPositionChanged(object sender, PositionChangedEventArgs e)
        {
            if (InvokeRequired) //debug cross thread;
            {
                BeginInvoke(new PositionChangedEventHandler(OnPositionChanged), new object[] { sender, e });
            }
            else
            {
                PositionChanged(sender, e);
            }
       }
       protected void OnTimer()
       {
           do
           {
               if (CurrentPosition < Duration)
               {
                   OnPositionChanged(this, new PositionChangedEventArgs(pos));
                    Thread.Sleep(50);
               }
               else
               {
                    Bass_ChannelStop(chan);
               }
               Application.DoEvents();
            } while (true);
        }
        #endregion;
       
        #region "EventHandler"
        public event PositionChangedEventHandler PositionChanged;
        #endregion;

        #region "Form Methods"
        private void Form1_Load(object sender, EventArgs e)
        {
            Bass_Init(-1, 44100, 0, this.Handle);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                strm = Bass_StreamCreateFile(ofd.FileName, 0, 0, 0);
                trackBar1.Maximum = (int)MaxPosition;
                label2.Text = TimeSpan.FromSeconds((double)trackBar1.Maximum).ToString().Substring(0, 8);
                button2_Click(sender, e);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Bass_ChannelPlay(strm, false);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Bass_ChannelPause(strm);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            Bass_ChannelStop(strm);
        }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            CurrentPosition = (double)trackBar1.Value;
        }
        public void Form1_PositionChanged(object sender, PositionChangedEventArgs e)
        {
            trackBar1.Value = (int)e.CurrentPos;
            label1.Text = TimeSpan.FromSeconds((double)trackBar1.Value).ToString().Substring(0, 8);
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Bass_Close();
        }
        #endregion
    }

    #region EventArgs
    public class PositionChangedEventArgs : EventArgs
    {
         double _pos = 0;
         public PositionChangedEventArgs(double pos) : base()
         {
             this._pos = pos;
         }
         public double CurrentPos
         {
             get
             {
                 return _pos;
             }
         }
    }
    #endregion

    #region Delegate
    public delegate void PositionChangedEventHandler(object sender, PositionChangedEventArgs e);
    #endregion

}
« Last Edit: 2 Sep '17 - 15:33 by sak2005 »

sak2005

  • Posts: 972
Tip: Using UIThread static class, for debug cross thread ::)

Code: [Select]
static class ControlExtensions
{
     static public void UIThread(this Control control, Action code)
     {
           if ( control.InvokeRequired )
           {
                control.BeginInvoke(code);
                return;
            }
            code.Invoke();
     }
}

Example:
Code: [Select]
protected void OnPositionChanged(object sender, PositionChangedEventArgs e)
{
      this.UIThread(delegate
      {
             if ( PositionChanged != null )
             {
                  PositionChanged(sender, e);
             }
             else
             {
                  return;
             }
      });
}
« Last Edit: 2 Sep '17 - 18:14 by sak2005 »

sak2005

  • Posts: 972
Tip: debug cross thread default

1. Using method is.. Control.CheckForIllegalCrossThreadCalls = false;

2. Delegate InvokeRequired;
 Example:
Code: [Select]
private void this_PositionChanged(object sender, PositionChangedEventArgs e )
{
     if(InvokeRequired)
     {
           BeginInvoke(new PositionChangedEventHandler(this_PositionChanged), new object[]{sender, e});
     }
     else
     {
           trackBar1.Value = (int)CurrentPosition;
           label1.Text = TimeSpan.FromSeconds((double)trackBar1.Value).ToString().Substring(0, 8);
     }
}
« Last Edit: 2 Sep '17 - 22:54 by sak2005 »

sak2005

  • Posts: 972
Tip: Using Threading Timer with PositionChangedEvent ::)

Code: [Select]
Public MustInherit Class IBASS
    Inherits Object
    Public MustOverride Function BASS_PluginLoad(ByVal dllName As String) As Integer
    Public MustOverride Function BASS_PluginFree(ByVal fhandle As Integer) As Boolean
    Public MustOverride Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BassInit, ByVal win As IntPtr) As Boolean
    Public MustOverride Function BASS_StreamCreateFile(ByVal strFile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BassFlag) As Integer
    Public MustOverride Function BASS_ChannelPlay(ByVal handle As Integer, ByVal restart As Boolean) As Boolean
    Public MustOverride Function BASS_ChannelPause(ByVal handle As Integer) As Boolean
    Public MustOverride Function BASS_ChannelStop(ByVal handle As Integer) As Boolean
    Public MustOverride Function BASS_Close() As Boolean
    Public MustOverride Function BASS_ChannelGetState(ByVal handle As Integer) As StateFlag
    Protected MustOverride Sub OnPositionChanged(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
    Protected MustOverride Sub OnTimer()
    Protected MustOverride Sub StartTimer()
    Protected MustOverride Sub ErrorMessage(ByVal hr As Integer, ByVal ex As String)
    Protected MustOverride Function StartTime() As Boolean
    Protected MustOverride Sub OnTimerPosition(ByVal state As Object)
    Public MustOverride ReadOnly Property Duration() As Double
    Public MustOverride ReadOnly Property MaxPosition() As Double
    Public MustOverride Property CurrentPosition() As Double
    Public MustOverride ReadOnly Property LevelLeft() As Integer
    Public MustOverride ReadOnly Property LevelRight() As Integer
    Public MustOverride ReadOnly Property IsPlaying() As Boolean
    Public Sub New()
        MyBase.New()
    End Sub
End Class
Public Class BASSCLASS
    Inherits IBASS
#Region "APIs Fields"
    Private Declare Auto Function _PluginLoad Lib "bass.dll" Alias "BASS_PluginLoad" (ByVal dllName As String, ByVal flags As BassFlag) As Integer
    Private Declare Auto Function _PluginFree Lib "bass.dll" Alias "BASS_pluginFree" (ByVal fhandle As Integer) As Boolean
    Private Declare Auto Function _Init Lib "bass.dll" Alias "BASS_Init" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As BassInit, ByVal win As IntPtr, ByVal clsid As IntPtr) As Boolean
    Private Declare Auto Function _StreamFree Lib "bass.dll" Alias "BASS_StreamFree" (ByVal handle As Integer) As Boolean
    Private Declare Auto Function _StreamCreateFile Lib "bass.dll" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal strFile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BassFlag) As Integer
    Private Declare Auto Function _ChannelPlay Lib "bass.dll" Alias "BASS_ChannelPlay" (ByVal handle As Integer, ByVal restart As Boolean) As Boolean
    Private Declare Auto Function _ChannelPause Lib "bass.dll" Alias "BASS_ChannelPause" (ByVal handle As Integer) As Boolean
    Private Declare Auto Function _ChannelStop Lib "bass.dll" Alias "BASS_ChannelStop" (ByVal handle As Integer) As Boolean
    Private Declare Auto Function _Free Lib "bass.dll" Alias "BASS_Free" () As Boolean
    Private Declare Auto Function _ChannelGetState Lib "bass.dll" Alias "BASS_ChannelIsActive" (ByVal handle As Integer) As StateFlag
    Private Declare Auto Function _ChannelBytes2Seconds Lib "bass.dll" Alias "BASS_ChannelBytes2Seconds" (ByVal handle As Integer, ByVal lenpos As Long) As Double
    Private Declare Auto Function _ChannelGetLength Lib "bass.dll" Alias "BASS_ChannelGetLength" (ByVal handle As Integer, ByVal mode As BassMode) As Long
    Private Declare Auto Function _ChannelGetPosition Lib "bass.dll" Alias "BASS_ChannelGetPosition" (ByVal handle As Integer, ByVal mode As BassMode) As Long
    Private Declare Auto Function _ChannelSeconds2Bytes Lib "bass.dll" Alias "BASS_ChannelSeconds2Bytes" (ByVal handle As Integer, ByVal pos As Double) As Long
    Private Declare Auto Function _ChannelSetPosition Lib "bass.dll" Alias "BASS_ChannelSetPosition" (ByVal handle As Integer, ByVal pos As Long, ByVal mode As BassMode) As Boolean
    Private Declare Auto Function _ChannelGetLevel Lib "bass.dll" Alias "BASS_ChannelGetLevel" (ByVal handle As Integer) As Integer
#End Region
#Region "Constructors Fields"
    Private thread As Thread
    Private len As Double
    Private pos As Double
    Private sfile As String
    Private chan As Integer
    Public Sub New()
        MyBase.New()
        Control.CheckForIllegalCrossThreadCalls = False
        Me.thread = Nothing
        Me.sfile = String.Empty
        Me.chan = 0
    End Sub
#End Region
#Region "Methods Fields"
    Public Overrides Function BASS_PluginLoad(ByVal dllName As String) As Integer
        Return _PluginLoad(dllName, BassFlag.BASS_UNICODE)
    End Function
    Public Overrides Function BASS_PluginFree(ByVal fhandle As Integer) As Boolean
        Return _PluginFree(fhandle)
    End Function
    Public Overrides Function BASS_Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BassInit, ByVal win As System.IntPtr) As Boolean
        If Not _Init(device, freq, flags, win, IntPtr.Zero) Then
            MsgBox("Error! Init", MsgBoxStyle.OkOnly, "")
        End If
    End Function
    Public Overrides Function BASS_StreamCreateFile(ByVal strFile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BassFlag) As Integer
        flags = flags Or BassFlag.BASS_UNICODE
        If sfile <> String.Empty Then _StreamFree(chan)
        sfile = strFile
        chan = _StreamCreateFile(False, sfile, offset, length, flags)
        ErrorMessage(chan, "File not support.")
        Return chan
    End Function
    Public Overrides Function BASS_ChannelPlay(ByVal handle As Integer, ByVal restart As Boolean) As Boolean
        If CBool(handle) Then
            StartTimer()
            Return _ChannelPlay(chan, restart)
        End If
    End Function
    Protected Overrides Function StartTime() As Boolean
        Dim callback As New Threading.TimerCallback(AddressOf OnTimerPosition)
        Dim threadTime As New Threading.Timer(callback)
        Return threadTime.Change(0, 100)
    End Function
    Protected Overrides Sub OnTimerPosition(ByVal state As Object)
        If CurrentPosition < Duration Then
            OnPositionChanged(Me, New PositionChangedEventArgs(pos))
        Else
            BASS_ChannelStop(chan)
        End If
        Application.DoEvents()
    End Sub
    Public Overrides Function BASS_ChannelPause(ByVal handle As Integer) As Boolean
        If CBool(handle) Then
            Return _ChannelPause(chan)
        End If
    End Function
    Public Overrides Function BASS_ChannelStop(ByVal handle As Integer) As Boolean
        If CBool(handle) Then
            CurrentPosition = 0
            Return _ChannelStop(chan)
        End If
    End Function
    Public Overrides Function BASS_Close() As Boolean
        If CBool(chan) Then
            If thread IsNot Nothing Then
                thread.Abort()
                thread.Join()
            End If
            Return _Free()
        End If
    End Function
    Public Overrides Function BASS_ChannelGetState(ByVal handle As Integer) As StateFlag
        Return _ChannelGetState(handle)
    End Function
    Protected Overrides Sub OnPositionChanged(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
        If PositionChangedEvent IsNot Nothing Then
            RaiseEvent PositionChanged(sender, e)
        End If
    End Sub
    Protected Overrides Sub OnTimer()
        Do
            If CurrentPosition < Duration Then
                OnPositionChanged(Me, New PositionChangedEventArgs(pos))
                Threading.Thread.Sleep(50)
            Else
                BASS_ChannelStop(chan)
            End If
            Application.DoEvents()
        Loop
    End Sub
    Protected Overrides Sub StartTimer()
        If thread Is Nothing Then
            thread = New Thread(AddressOf Me.OnTimer)
            thread.IsBackground = True
            thread.Priority = ThreadPriority.Normal
            thread.Start()
        End If
    End Sub
    Protected Overrides Sub ErrorMessage(ByVal hr As Integer, ByVal ex As String)
        If Not CBool(hr) Then
            MsgBox("Error! " & ex, MsgBoxStyle.OkOnly, "")
            Return
        End If
    End Sub
#End Region
#Region "Properties Fields"
    Public Overrides ReadOnly Property Duration() As Double
        Get
            len = _ChannelBytes2Seconds(chan, _ChannelGetLength(chan, BassMode.BASS_POS_BYTE))
            Return len
        End Get
    End Property
    Public Overrides ReadOnly Property MaxPosition() As Double
        Get
            Return Duration()
        End Get
    End Property
    Public Overrides Property CurrentPosition() As Double
        Get
            pos = _ChannelBytes2Seconds(chan, _ChannelGetPosition(chan, BassMode.BASS_POS_BYTE))
            Return pos
        End Get
        Set(ByVal value As Double)
            pos = value
            _ChannelSetPosition(chan, _ChannelSeconds2Bytes(chan, pos), BassMode.BASS_POS_BYTE)
        End Set
    End Property
    Public Overrides ReadOnly Property LevelLeft() As Integer
        Get
            If IsPlaying Then
                Return _ChannelGetLevel(chan) And 65535
            End If
            Return 0
        End Get
    End Property
    Public Overrides ReadOnly Property LevelRight() As Integer
        Get
            If IsPlaying Then
                Return (_ChannelGetLevel(chan) >> 16) And 65535
            End If
            Return 0
        End Get
    End Property
    Public Overrides ReadOnly Property IsPlaying() As Boolean
        Get
            If BASS_ChannelGetState(chan) = StateFlag.Playing Then
                Return True
            End If
            Return False
        End Get
    End Property
#End Region
#Region "EventHandler"
    Public Event PositionChanged As PositionChangedEventHandler
#End Region
End Class
Public Class PositionChangedEventArgs
    Inherits EventArgs
    Private _pos As Double
    Public Sub New(ByVal pos As Double)
        MyBase.New()
        Me._pos = pos
    End Sub
    Public Overridable ReadOnly Property CurrentPos() As Double
        Get
            Return _pos
        End Get
    End Property
End Class
#Region "Delegate"
Public Delegate Sub PositionChangedEventHandler(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
#End Region
#Region "Flags"
<Flags()> _
Public Enum StateFlag
    Stopped = 0
    Playing = 1
    Stalled = 2
    Paused = 3
End Enum
<Flags()> _
Public Enum BassInit
    BASS_DEVICE_DEFAULT = 0
End Enum
<Flags()> _
Public Enum BassFlag
    BASS_DEFAULT = 0
    BASS_UNICODE = -2147483648
End Enum
<Flags()> _
Public Enum BassMode
    BASS_POS_BYTE = 0
End Enum
#End Region

« Last Edit: 3 Sep '17 - 06:07 by sak2005 »

sak2005

  • Posts: 972
Example:
Code: [Select]
Option Explicit Off
Option Strict On

Imports System
Imports System.Windows.Forms
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices

Public Class Form1
    Private Bass As New BASSCLASS
    Private fplug As Integer
    Private strm As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Bass.BASS_Init(-1, 44100, 0, Me.Handle)
        fplug = Bass.BASS_PluginLoad("bass_aac.dll")
        AddHandler Bass.PositionChanged, AddressOf Bass_PositionChanged
    End Sub

    Private Sub Bass_PositionChanged(ByVal sender As System.Object, ByVal e As PositionChangedEventArgs)
        Label1.Text = Bass.BASS_ChannelGetState(strm).ToString
        TrackBar1.Value = CInt(e.CurrentPos)
        lblPosition.Text = TimeSpan.FromSeconds(CDbl(TrackBar1.Value)).ToString.Substring(0, 8)
        ProgressBar1.Value = Bass.LevelLeft
        ProgressBar2.Value = Bass.LevelRight
    End Sub

    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            strm = Bass.BASS_StreamCreateFile(OpenFileDialog1.FileName, 0, 0, 0)
            TrackBar1.Maximum = CInt(Bass.MaxPosition)
            lblDuration.Text = TimeSpan.FromSeconds(CDbl(TrackBar1.Maximum)).ToString.Substring(0, 8)
            btnPlay_Click(sender, e)
        End If
    End Sub

    Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
        Bass.BASS_ChannelPlay(strm, False)
    End Sub

    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        Bass.BASS_ChannelPause(strm)
    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
        Bass.BASS_ChannelStop(strm)
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Bass.CurrentPosition = TrackBar1.Value
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Bass.BASS_Close()
    End Sub
End Class

sak2005

  • Posts: 972
Tip: Bass Volume and Balance set Level , PositionChangedEvent, Using.. Background Worker
       and Bass SetPlayRepeat method, If set True then playing is looping. ::)

This codes is long code, cann't post, DownLoad ;D Clickhere
« Last Edit: 4 Sep '17 - 13:18 by sak2005 »

sak2005

  • Posts: 972
Tip: Sample codes : FFMedia Class ::)

Info:
Convert Audio and video format with.. FFmpeg :)
Show file info with.. FFprobe :D
Playing media file with.. FFplay ;D

Note: Code is not complete yet. Will fix it later. 8)

Long code cann't post, spritting code to part1 and part2

Code: [Select]
'--------------------------------------Part1--------------------------------------------------------------------------
Option Explicit Off
Option Strict On
Imports System
Imports System.IO
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Diagnostics
Public Class FFMedia
    Inherits Object
#Region "Constructors Fields"
    Private _BackgroundWorker As BackgroundWorker = Nothing
    Private _Process As Process = Nothing
    Private _Input As String
    Private _Options As String
    Private _Output As String
    Private _FileName As String
    Public Sub New()
        MyBase.New()
        Control.CheckForIllegalCrossThreadCalls = False
        If Not File.Exists(Path.Combine(Application.StartupPath, "ffmpeg.exe")) Then
            FileIO.FileSystem.WriteAllBytes(Path.Combine(Application.StartupPath, "ffmpeg.exe"), My.Resources.ffmpeg, True)
        End If
        If Not File.Exists(Path.Combine(Application.StartupPath, "ffprobe.exe")) Then
            FileIO.FileSystem.WriteAllBytes(Path.Combine(Application.StartupPath, "ffprobe.exe"), My.Resources.ffprobe, True)
        End If
        If Not File.Exists(Path.Combine(Application.StartupPath, "ffplay.exe")) Then
            FileIO.FileSystem.WriteAllBytes(Path.Combine(Application.StartupPath, "ffplay.exe"), My.Resources.ffplay, True)
        End If
        Me._BackgroundWorker = New BackgroundWorker
        _BackgroundWorker.WorkerReportsProgress = True
        _BackgroundWorker.WorkerSupportsCancellation = True
        Me._Process = New Process
        Me._Input = String.Empty
        Me._Options = String.Empty
        Me._Output = String.Empty
        Me._FileName = String.Empty
        AddHandler _BackgroundWorker.DoWork, New System.ComponentModel.DoWorkEventHandler(AddressOf BackgroundWorker1_DoWork)
        AddHandler _BackgroundWorker.ProgressChanged, New System.ComponentModel.ProgressChangedEventHandler(AddressOf _BackgroundWorker_ProgressChanged)
        AddHandler _BackgroundWorker.RunWorkerCompleted, New System.ComponentModel.RunWorkerCompletedEventHandler(AddressOf BackgroundWorker1_RunWorkerCompleted)
    End Sub
#End Region
    Protected Overrides Sub Finalize()
        Try
            Dim Proc As Process() = Process.GetProcessesByName("ffmpeg")
            For Each p As Process In Proc
                If p.ProcessName = "ffmpeg" Then
                    Try
                        _Process.Kill()
                    Catch ex As Exception
                        Exit Try
                    End Try
                End If
                If p.ProcessName = "ffprobe" Then
                    Try
                        _Process.Kill()
                    Catch ex As Exception
                        Exit Try
                    End Try
                End If
                If p.ProcessName = "ffplay" Then
                    Try
                        _Process.Kill()
                    Catch ex As Exception
                        Exit Try
                    End Try
                End If
            Next p
            _Process = Nothing
        Catch
            Exit Try
        End Try
        MyBase.Finalize()
    End Sub
#Region "FFmpeg Methods Fields"
    Public Overridable Overloads Sub Convert(ByVal Input As String, ByVal Output As String, ByVal Report As Control, Optional ByVal SaveOverWrite As Boolean = False)
        _Input = Input
        _Output = Output
        _Process.StartInfo.FileName = "ffmpeg.exe"
        If SaveOverWrite Then
            _Process.StartInfo.Arguments = "-y -i """ & _Input & """ """ & _Output
        Else
            _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Output
        End If
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            Else
                Report.Text = "Converting: " & _Process.StandardError.ReadLine
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream
        Report.Text = String.Empty
    End Sub
    Public Overridable Overloads Sub Convert(ByVal Input As String, ByVal Output As String, Optional ByVal SaveOverWrite As Boolean = False)
        _Input = Input
        _Output = Output
        _Process.StartInfo.FileName = "ffmpeg.exe"
        If SaveOverWrite Then
            _Process.StartInfo.Arguments = "-y -i """ & _Input & """ """ & _Output
        Else
            _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Output
        End If
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = False
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited
    End Sub
    Public Overridable Overloads Sub Convert(ByVal Input As String, ByVal Options As String, ByVal Output As String, Optional ByVal SaveOverWrite As Boolean = False)
        _Input = Input
        _Options = Options
        _Output = Output
        _Process.StartInfo.FileName = "ffmpeg.exe"
        If SaveOverWrite Then
            _Process.StartInfo.Arguments = "-y -i """ & _Input & """ """ & _Options & """ """ & _Output
        Else
            _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Options & """ """ & _Output
        End If
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = False
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited
    End Sub
« Last Edit: 5 Sep '17 - 03:14 by sak2005 »

sak2005

  • Posts: 972
Code: [Select]
'---------------------------------------Part2----------------------------------------------------------------
    Public Overridable Overloads Sub Convert(ByVal Input As String, ByVal Options As String, ByVal Output As String, ByVal Report As Control, Optional ByVal SaveOverWrite As Boolean = False)
        _Input = Input
        _Options = Options
        _Output = Output
        _Process.StartInfo.FileName = "ffmpeg.exe"
        If SaveOverWrite Then
            _Process.StartInfo.Arguments = "-y -i """ & _Input & """ """ & _Options & """ """ & _Output
        Else
            _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Options & """ """ & _Output
        End If
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            Else
                Report.Text = "Converting: " & _Process.StandardError.ReadLine
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream
        Report.Text = String.Empty
    End Sub
    Public Overridable Overloads Sub GetMediaInfo(ByVal Input As String, ByVal Report As Control)
        _Input = Input
        _Process.StartInfo.FileName = "ffprobe.exe"
        _Process.StartInfo.Arguments = "-i """ & _Input & """"
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            Else
                Report.Text = _Process.StandardError.ReadLine
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream Or Report.Text = String.Empty
    End Sub
    Public Overridable Overloads Sub Player(ByVal Input As String, ByVal Report As Control)
        _Input = Input
        _Process.StartInfo.FileName = "ffplay.exe"
        _Process.StartInfo.Arguments = "-i """ & _Input & """"
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            Else
                Report.Text = _Process.StandardError.ReadLine
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream Or Report.Text = String.Empty
    End Sub
    Public Overridable Overloads Sub Player(ByVal Input As String, ByVal Options As String, ByVal Report As Control)
        _Input = Input
        _Options = Options
        _Process.StartInfo.FileName = "ffplay.exe"
        _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Options
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            Else
                Report.Text = _Process.StandardError.ReadLine
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream Or Report.Text = String.Empty
    End Sub
    Public Overridable Overloads Sub Player(ByVal Input As String, ByVal Options As String)
        _Input = Input
        _Options = Options
        _Process.StartInfo.FileName = "ffplay.exe"
        _Process.StartInfo.Arguments = "-i """ & _Input & """ """ & _Options
        _Process.StartInfo.UseShellExecute = False
        _Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        _Process.StartInfo.RedirectStandardError = True
        _Process.StartInfo.CreateNoWindow = True
        _Process.Start()
        Do
            If _BackgroundWorker.CancellationPending Then
                _Process.Kill()
                Exit Do
            End If
            Application.DoEvents()
        Loop Until _Process.HasExited Or _Process.StandardError.EndOfStream
    End Sub
    Public Overridable Sub StartConvert()
        _BackgroundWorker.RunWorkerAsync()
    End Sub
    Public Overridable Sub CancelConvert()
        _BackgroundWorker.CancelAsync()
    End Sub
    Public Overridable Sub Close()
        Try
            _Process.Kill()
        Catch ex As Exception
            Exit Try
        End Try
    End Sub
#End Region
#Region "FFmpeg Properties Fields"
    Public Property Input() As String
        Get
            Return _Input
        End Get
        Set(ByVal value As String)
            _Input = value
        End Set
    End Property
    Public Property Output() As String
        Get
            Return _Output
        End Get
        Set(ByVal value As String)
            _Output = value
        End Set
    End Property
    Public Property Options() As String
        Get
            Return _Options
        End Get
        Set(ByVal value As String)
            _Options = value
        End Set
    End Property
    Public Property Filename() As String
        Get
            Return _FileName
        End Get
        Set(ByVal value As String)
            _FileName = value
        End Set
    End Property
#End Region
#Region "FFmpeg Events Fields"
    Public Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        If _BackgroundWorker IsNot Nothing Then
            RaiseEvent DoWorkChanged(sender, e)
        End If
    End Sub
    Public Sub _BackgroundWorker_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
        If _BackgroundWorker IsNot Nothing Then
            RaiseEvent ProgressChanged(sender, e)
        End If
    End Sub
    Public Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
        If _BackgroundWorker IsNot Nothing Then
            RaiseEvent CompleteChanged(sender, e)
        End If
    End Sub
    Public Event DoWorkChanged As System.ComponentModel.DoWorkEventHandler
    Public Event ProgressChanged As System.ComponentModel.ProgressChangedEventHandler
    Public Event CompleteChanged As System.ComponentModel.RunWorkerCompletedEventHandler
#End Region
End Class

sak2005

  • Posts: 972
Tip: Bath CommandLine Text Report ::) for ffmpeg, ffprobe, and ffplay

Example: Get help.txt and get sound info.txt

ffmpeg.bat
Code: [Select]
@echo off
ffmpeg -i -h >ffmpeg_help.txt
exit

ffprobe.bat
Code: [Select]
@echo off
ffprobe -i  sound.wav -show_format >sound_Info.txt
pause

ffplay.bat : Play loop and not show DSP
Code: [Select]
@echo off
ffplay -loop 3 -i sound.wav -nodisp
exit

ffplay.bat : Play loop and not show DSP and set time song end at 15 seconds.
Code: [Select]
@echo off
ffplay -loop 3 -t 15 -i sound.wav -nodisp
exit
« Last Edit: 7 Sep '17 - 03:22 by sak2005 »

sak2005

  • Posts: 972
Console Application

BPlayer.exe source code  ::) Run on the Command prompt with file.bat
Same as MPlayer or FFplay

But! long codes , cann't post, spritting code to Part1 and Part2

Part1:
Code: [Select]
using System;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace BPlayer
{
    class Program
    {
        [DllImport("bass.dll")]
        private static extern bool BASS_Init(int device, int freq, BASSInit flags, IntPtr win, IntPtr clsid);
        [DllImport("bass.dll")]
        private static extern bool BASS_StreamFree(int handle);
        [DllImport("bass.dll", CharSet = CharSet.Auto)]
        private static extern int BASS_StreamCreateFile(bool mem, string file, long offset, long length, BASSFlag flags);
        [DllImport("bass.dll")]
        private static extern bool BASS_ChannelPlay(int handle, bool restart);
        [DllImport("bass.dll")]
        private static extern bool BASS_ChannelPause(int handle);
        [DllImport("bass.dll")]
        private static extern bool BASS_ChannelStop(int handle);
        [DllImport("bass.dll")]
        private static extern BASSActive BASS_ChannelIsActive(int handle);
        [DllImport("bass.dll")]
        private static extern double BASS_ChannelBytes2Seconds(int handle, long lenpos);
        [DllImport("bass.dll")]
        private static extern long BASS_ChannelGetLength(int handle, BASSMode mode);
        [DllImport("bass.dll")]
        private static extern long BASS_ChannelGetPosition(int handle, BASSMode mode);
        [DllImport("bass.dll")]
        private static extern bool BASS_Free();
        [DllImport("bass.dll")]
        private static extern long BASS_ChannelSeconds2Bytes(int handle, double pos);
        [DllImport("bass.dll")]
        private static extern bool BASS_ChannelSetPosition(int handle, long pos, BASSMode mode);
        [DllImport("bass.dll")]
        private static extern float BASS_GetCPU();
        [DllImport("bass_aac.dll", CharSet = CharSet.Auto)]
        private static extern int BASS_MP4_StreamCreateFile(bool mem, string file, long offset, long length, BASSFlag flags);
        [DllImport("basswma.dll", CharSet = CharSet.Auto)]
        private static extern int BASS_WMA_StreamCreateFile(bool mem, string file, long offset, long length, BASSFlag flags);
        private static BackgroundWorker backgroundworker = null;
        static string str;
        static string file;
        static double pos;
        static int loop;
        static bool help;
        static bool pl;
        static  bool Done;
        static bool pause;
        static bool ofs;
        static int chan;
        static void Main(string[] args)
        {
            Console.Title = "BPlayer";
            if (!BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, IntPtr.Zero))
            { Console.WriteLine("Not found bass.dll"); Console.ReadLine(); return; }
            backgroundworker = new BackgroundWorker();
            backgroundworker.DoWork += new System.ComponentModel.DoWorkEventHandler(backgroundworker_DoWork);
            str = string.Empty;
            file = string.Empty;
            pos = 0;
            loop = 0;
            pl = false;
            help = false;
            pause = false;
            ofs = false;
            chan = 0;
            foreach (var item in args)
            {
                str = item;
                if (str.Contains("-loop") | str.Contains("-repeat"))
                {
                    loop = 4;
                }
                else if (str.Contains("-i"))
                {
                    pl = true;
                }
                else if (str.Contains("-ofs"))
                {
                    ofs = true;
                }
                else
                {
                    if (str.Contains("-h") | str.Contains("-help"))
                    {
                        help = true;
                    }
                }
            }
            if (help == true)
            {
                Console.WriteLine("==========Info===========");
                Console.WriteLine("Input:");
                Console.WriteLine("BPlayer [Option] FileName");
                Console.WriteLine("Option:");
                Console.WriteLine("-i  PlayOnLoad");
                Console.WriteLine("-h or -help  Show Infomation");
                Console.WriteLine("-loop or -repeat  PlayNoneStop");
                Console.WriteLine("-ofs  Sync End Exit Console");
                Console.WriteLine("keyboard:");
                Console.WriteLine("Enter or SpaceBar  Playing");
                Console.WriteLine("P  Toggle Play/Pause");
                Console.WriteLine("Q or Esc  Stopped");
                Console.WriteLine("Arrow Left Right  SetPosition");
                Console.WriteLine("X  Force Exit Process Console");
                Console.WriteLine("===========Keyb==============");
                Console.WriteLine("Press Enter to exit Info");
                Console.ReadLine();
           }
                if (str == string.Empty | !str.Contains(".")) { return; }
                file = Path.Combine(Application.StartupPath, str);
                Console.WriteLine("FileName: " + Path.GetFileName(file));
                if (Path.GetExtension(file) == ".mp4")
                {
                    if (loop == 4)
                    {
                        chan = BASS_MP4_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE | BASSFlag.BASS_MUSIC_LOOP);
                    }
                    else
                    {
                        chan = BASS_MP4_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE);
                    }
                }
                else if (Path.GetExtension(file) == ".wma")
                {
                    if (loop == 4)
                    {
                        chan = BASS_WMA_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE | BASSFlag.BASS_MUSIC_LOOP);
                    }
                    else
                    {
                        chan = BASS_WMA_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE);
                    }
                }
                else
                {
                    if (loop == 4)
                    {
                        chan = BASS_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE | BASSFlag.BASS_MUSIC_LOOP);
                    }
                    else
                    {
                        chan = BASS_StreamCreateFile(false, file, 0, 0, BASSFlag.BASS_UNICODE);
                    }
                }
                if (chan != 0)
                {
                    double duration = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, 0));
                    Console.WriteLine("DurationTime: " + TimeSpan.FromSeconds(duration).ToString().Substring(0, 8));
                    if (pl == true)
                    {
                        BASS_ChannelPlay(chan, false);
                    }
                    backgroundworker.RunWorkerAsync();
                }
                else
                {
                    MessageBox.Show("file not support");
                    return;
                }
                while (true)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Enter | key.Key == ConsoleKey.Spacebar)
                    {
                        if (chan != 0)
                        {
                            if (BASS_ChannelIsActive(chan) == BASSActive.Stopped)
                            {
                                BASS_ChannelPlay(chan, true);
                            }
                        }
                    }
                    else if (key.Key == ConsoleKey.P)
                    {
                        if (chan != 0)
                        {
                            if (BASS_ChannelIsActive(chan) == BASSActive.Playing)
                            {
                                BASS_ChannelPause(chan);
                            }
                            else
                            {
                                if (BASS_ChannelIsActive(chan) == BASSActive.Paused)
                                {
                                    BASS_ChannelPlay(chan, false);
                                }
                            }
                        }
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        if (chan != 0)
                        {
                            if (BASS_ChannelIsActive(chan) == BASSActive.Playing | BASS_ChannelIsActive(chan) == BASSActive.Paused)
                            {
                                pos--;
                                if (pos < 1) { pos = 0; }
                                BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, pos), BASSMode.BASS_POS_BYTE);
                            }
                        }
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        if (chan != 0)
                        {
                            if (BASS_ChannelIsActive(chan) == BASSActive.Playing | BASS_ChannelIsActive(chan) == BASSActive.Paused)
                            {
                                pos++;
                                double lensec = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, 0));
                                if (pos >= lensec)
                                {
                                    pos = 0;
                                    lensec = pos;
                                    BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, 0), BASSMode.BASS_POS_BYTE);
                                    BASS_ChannelStop(chan);
                                }
                                BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, pos), BASSMode.BASS_POS_BYTE);
                            }
                        }
                    }
                    else if (key.Key == ConsoleKey.X)
                    {
                        Process[] proc = Process.GetProcessesByName("Bplayer");
                        foreach (var item in proc)
                        {
                            item.Kill();
                        }
                    }
                    else
                    {
                        if (chan != 0)
                        {
                            if (key.Key == ConsoleKey.Q | key.Key == ConsoleKey.Escape)
                            {
                                pos = 0;
                                BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, 0), 0);
                                BASS_ChannelStop(chan);
                            }
                        }
                    }
                    Application.DoEvents();
                }
            }
        ~Program()
        {
            if (chan != 0) { BASS_Free(); }
        }
« Last Edit: 10 Sep '17 - 07:12 by sak2005 »

sak2005

  • Posts: 972
Part2:
Code: [Select]
public static void backgroundworker_DoWork(object sender, DoWorkEventArgs e)
        {
            do
            {
                Console.Clear();
                Console.WriteLine("==================Info==================");
                Console.WriteLine("FileName: " + Path.GetFileName(file));
                double duration = BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, 0));
                Console.WriteLine("DurationTime: " + TimeSpan.FromSeconds(duration).ToString().Substring(0, 8));
                double currentposition =  BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetPosition(chan, 0));
                int percent = (int)((currentposition / duration) * 100);
                if (currentposition < duration)
                {
                    Console.WriteLine("PositionTime: " + TimeSpan.FromSeconds(currentposition).ToString().Substring(0, 8));
                    Console.WriteLine("Status: " + BASS_ChannelIsActive(chan).ToString());
                    Console.WriteLine("Progression: " + percent + "%");
                    Console.WriteLine("CPU: " + BASS_GetCPU().ToString("#0.00"));
                    Console.WriteLine("==================Keyb==================");
                    Console.WriteLine("Press Enter or SpaceBar to Playing");
                    Console.WriteLine("Press Arrow Left Right to ChangePosition");
                    Console.WriteLine("Press P to Toggle Play/Pause");
                    Console.WriteLine("Press Q or Esc to Stopped");
                    Console.WriteLine("Press X to Exit Console");
                }
                else
                {
                    Console.WriteLine("PositionTime: " + TimeSpan.FromSeconds(currentposition).ToString().Substring(0, 8));
                    Console.WriteLine("Status: " + BASS_ChannelIsActive(chan).ToString());
                    Console.WriteLine("Progression: " + percent + "%");
                    Console.WriteLine("CPU: " + BASS_GetCPU().ToString("#0.00"));
                    Console.WriteLine("==================Keyb==================");
                    Console.WriteLine("Press Enter or SpaceBar to Playing");
                    Console.WriteLine("Press Arrow Left Right to ChangePosition");
                    Console.WriteLine("Press P to Toggle Play/Pause");
                    Console.WriteLine("Press Q or Esc to Stopped");
                    Console.WriteLine("Press X to Exit Console");
                    pos = 0;
                    BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, 0), 0);
                    BASS_ChannelStop(chan);
                    if (ofs == true)
                    {
                        Process[] proc = Process.GetProcessesByName("Bplayer");
                        foreach (var item in proc)
                        {item.Kill();}
                    }
                }
                Thread.Sleep(1000);
                Application.DoEvents();
               
            } while (true);
        }
        public enum BASSInit
        {
            BASS_DEVICE_DEFAULT = 0
        }
        public enum BASSFlag
        {
            BASS_DEFAULT = 0,
            BASS_UNICODE = -2147483648,
            BASS_MUSIC_LOOP = 4
        }
        public enum BASSMode
        {
            BASS_POS_BYTE = 0
        }
        public enum BASSActive
        {
            Stopped = 0,
            Playing = 1,
            Installed = 2,
            Paused = 3
        }
    }
}

sak2005

  • Posts: 972
BPlayer.bat sample:

Not play on load
Code: [Select]
echo off
BPlayer song.mp3

Play on load
Code: [Select]
echo off
BPlayer -i song.mp3

Play repeat
Code: [Select]
echo off
BPlayer -loop -i song.mp3

Sync end exit console
Code: [Select]
echo off
BPlayer -ofs  -i song.mp3



sak2005

  • Posts: 972
Tip: Serach bass dlls in the local dir, if not found bass dlls in the curr dir. ::)

Example:
Code: [Select]
Public Sub New()
        MyBase.New()
     
        Dim BASSPATH As String = Path.Combine(Application.StartupPath, "bass.dll")
        Dim MP4PATH As String = Path.Combine(Application.StartupPath, "bass_aac.dll")
        Dim WMAPATH As String = Path.Combine(Application.StartupPath, "basswma.dll")

        If Not File.Exists(BASSPATH) Then
            For Each i In FileIO.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchAllSubDirectories, "bass.dll")
                If i.Contains("bass.dll") Then
                    File.Copy(i, BASSPATH, True)
                    Exit For
                End If
            Next i
        End If
        If Not File.Exists(MP4PATH) Then
            For Each i In FileIO.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchAllSubDirectories, "bass_aac.dll")
                If i.Contains("bass_aac.dll") Then
                    File.Copy(i, MP4PATH, True)
                    Exit For
                End If
            Next i
        End If
        If Not File.Exists(WMAPATH) Then
            For Each i In FileIO.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchAllSubDirectories, "basswma.dll")
                If i.Contains("basswma.dll") Then
                    File.Copy(i, WMAPATH, True)
                    Exit For
                End If
            Next i
        End If

        Try
            BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, hWnd, IntPtr.Zero)
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
        Try
            BASS_PluginLoad("bass_aac.dll", BASSFlag.BASS_UNICODE)
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
        Try
            BASS_PluginLoad("basswma.dll", BASSFlag.BASS_UNICODE)
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

sak2005

  • Posts: 972
Tip: Using.. Directive (#If) , for search and fix path to bass dlls. ::)

Example:
Code: [Select]
#Const DOWNLOAD = "C:\Documents and Settings\Administrator\My Documents\Downloads\Compressed\bass24\bass.dll"
#Const DESKTOP = "C:\Documents and Settings\Administrator\Desktop\bass.dll"

Public Class MYBASS
    Inherits Object

#If DEBUG = -1 Then
    Private Const BASSDLL As String = "bass.dll"
#ElseIf DOWNLOAD = "C:\Documents and Settings\Administrator\My Documents\Downloads\Compressed\bass24\bass.dll" Then
    Private Const BASSDLL As String = "C:\Documents and Settings\Administrator\My Documents\Downloads\Compressed\bass24\bass.dll"
#Else
    #If DESKTOP = "C:\Documents and Settings\Administrator\Desktop\bass.dll" Then
       Private Const BASSDLL As String = "C:\Documents and Settings\Administrator\Desktop\bass.dll"
    #End If
#End If

   <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_PluginLoad")> _
    Private Shared Function _PluginLoad(ByVal pin As String, ByVal flags As BASSFlag) As Integer
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_PluginFree")> _
    Private Shared Function _PluginFree(ByVal fhandle As Integer) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_Init")> _
    Private Shared Function _Init(ByVal device As Integer, ByVal freq As Integer, ByVal flags As BASSInit, ByVal win As IntPtr, ByVal clsid As IntPtr) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_StreamFree")> _
    Private Shared Function _StreamFree(ByVal handle As Integer) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_StreamCreateFile")> _
    Private Shared Function _StreamCreateFileUnicode(ByVal mem As Boolean, ByVal strFile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_StreamCreateFile")> _
    Private Shared Function _StreamCreateFileMemory(ByVal mem As Boolean, ByVal strFile As IntPtr, ByVal offset As Long, ByVal length As Long, ByVal flags As BASSFlag) As Integer
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_ChannelPlay")> _
    Private Shared Function _ChannelPlay(ByVal handle As Integer, ByVal restart As Boolean) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_ChannelPause")> _
    Private Shared Function _ChannelPause(ByVal handle As Integer) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_ChannelStop")> _
    Private Shared Function _ChannelStop(ByVal handle As Integer) As Boolean
    End Function
    <DllImport(BASSDLL, CharSet:=CharSet.Auto, EntryPoint:="BASS_Free")> _
    Private Shared Function _Free() As Boolean
    End Function

End Class
« Last Edit: 15 Sep '17 - 16:30 by sak2005 »

sak2005

  • Posts: 972
Tip: How to scrolling position in the console application. ::)

1. created operater is.. pos as double
2. created value position is.. vPos as double
3. set maxValue position is.. vPos = duration or maxposition.
4. update position is.. vPos = currentposition.
5.in the scroll left arrow add codes is.. pos = vPos -1 and setposition(pos)
6.in the scroll right arrow add codes is.. pos = vPos +1 and setposition(pos)

Example:
Code: [Select]
'Console Application (bplayback.exe)
Module Module1
    Private WithEvents tDowork As New System.ComponentModel.BackgroundWorker
    Private keys As ConsoleKeyInfo
    Private args As String()
    Private a, f As String
    Private pos, vPos As Double 'pos is operater, vPos is currentPos
    Private repeat As Boolean
    Private chan As Integer

    Sub Main()
        Player.BASS_Init(-1, 44100, 0, IntPtr.Zero, IntPtr.Zero)
        args = Environment.GetCommandLineArgs()
        If args.Length <= 1 Then Return
        For Each i In args
            If i.Contains(".") Then
                f = i
            ElseIf i.Contains("-") Then
                a = i
            End If
        Next i
        If a = "-loop" Then
            repeat = True
        Else
            repeat = False
        End If
        If repeat Then
            chan = Player.BASS_StreamCreateFile(f, 0, 0, 0 Or 4)
        Else
            chan = Player.BASS_StreamCreateFile(f, 0, 0, 0)
        End If
        tDowork.RunWorkerAsync()
        vPos = Player.MaxPosition 'set maxValue currentPos
        Player.BASS_ChannelPlay(chan, False)
        Do
            keys = Console.ReadKey(True)
            If keys.Key = ConsoleKey.Enter Then
                Player.BASS_ChannelPlay(chan, False)
            ElseIf keys.Key = ConsoleKey.P Then
                Player.BASS_ChannelPause(chan)
            ElseIf keys.Key = ConsoleKey.Spacebar Then
                If Player.BASS_ChannelIsActive(chan) = BASSActive.Playing Then
                    Player.BASS_ChannelPause(chan)
                Else
                    If Player.BASS_ChannelIsActive(chan) = BASSActive.Paused Then
                        Player.BASS_ChannelPlay(chan, False)
                    End If
                End If
            ElseIf keys.Key = ConsoleKey.Q Or keys.Key = ConsoleKey.End Then
                Player.SetPosition(0)
                Player.BASS_ChannelStop(chan)
                pos = Player.CurrentPosition
            ElseIf keys.Key = ConsoleKey.Home Then
                Player.SetPosition(0)
                pos = 0
            ElseIf keys.Key = ConsoleKey.LeftArrow Then
                pos = vPos - 1  'scroll down currentPos
                Player.SetPosition(pos)
            ElseIf keys.Key = ConsoleKey.RightArrow Then
                pos = vPos + 1 'scroll up currentPos
                Player.SetPosition(pos)
            ElseIf keys.Key = ConsoleKey.Escape Then
                Player.BASS_Free()
                Exit Do
            End If
            Threading.Thread.Sleep(10)
        Loop While True
    End Sub

    Private Sub tDowork_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles tDowork.DoWork
LIN:
        Do While True
            Threading.Thread.Sleep(100)
            Console.Clear()
            Console.WriteLine("   FileName: " & f)
            Console.WriteLine("CurrentFile: " & CInt(Player.CurrentPosition) & "/" & CInt(Player.Duration))
            Console.WriteLine("CurrentTime: " & TimeSpan.FromSeconds(Player.CurrentPosition).ToString.Substring(0, 8) & "/" & TimeSpan.FromSeconds(Player.Duration).ToString.Substring(0, 8))
            Console.WriteLine("     Status: " & Player.BASS_ChannelIsActive(chan).ToString)
            Console.WriteLine("Progression: " & CInt((Player.CurrentPosition / Player.Duration) * 100) & "%")
            vPos = Player.CurrentPosition 'update currentPos
            If Player.CurrentPosition > 0 Then
                If Player.CurrentPosition >= Player.Duration Then
                    If repeat Then
                        pos = 0
                        GoTo LIN
                    End If
                    Dim proc As Process()
                    proc = Process.GetProcessesByName("bplayback")
                    For Each i In proc
                        Player.BASS_Free()
                        i.Kill()
                    Next i
                End If
            End If
        Loop
    End Sub
End Module

Class Player
    Public Declare Auto Function BASS_Init Lib "bass" (ByVal device As Integer, ByVal freq As Integer, ByVal flags As Integer, ByVal win As IntPtr, ByVal clsid As IntPtr) As Boolean
    Private Declare Auto Function _StreamCreateFile Lib "bass" Alias "BASS_StreamCreateFile" (ByVal mem As Boolean, ByVal sfile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As Integer) As Integer
    Public Declare Auto Function BASS_ChannelPlay Lib "bass" (ByVal handle As Integer, ByVal restart As Boolean) As Boolean
    Public Declare Auto Function BASS_ChannelPause Lib "bass" (ByVal handle As Integer) As Boolean
    Public Declare Auto Function BASS_ChannelStop Lib "bass" (ByVal handle As Integer) As Boolean
    Public Declare Auto Function BASS_ChannelIsActive Lib "bass" (ByVal handle As Integer) As BASSActive
    Private Declare Auto Function BASS_ChannelBytes2Seconds Lib "bass" (ByVal handle As Integer, ByVal lenpos As Long) As Double
    Private Declare Auto Function BASS_ChannelGetLength Lib "bass" (ByVal handle As Integer, ByVal mode As Integer) As Long
    Private Declare Auto Function BASS_ChannelGetPosition Lib "bass" (ByVal handle As Integer, ByVal mode As Integer) As Long
    Private Declare Auto Function BASS_ChannelSeconds2Bytes Lib "bass" (ByVal handle As Integer, ByVal pos As Double) As Long
    Private Declare Auto Function BASS_ChannelSetPosition Lib "bass" (ByVal handle As Integer, ByVal pos As Long, ByVal mode As Integer) As Long
    Public Declare Auto Function BASS_Free Lib "bass" () As Boolean
    Private Shared chan As Integer
    Public Shared Function BASS_StreamCreateFile(ByVal sfile As String, ByVal offset As Long, ByVal length As Long, ByVal flags As Integer) As Integer
        flags = flags Or -2147483648
        chan = _StreamCreateFile(False, sfile, offset, length, flags)
        Return chan
    End Function
    Public Shared Function SetPosition(ByVal pos As Double) As Boolean
        Return BASS_ChannelSetPosition(chan, BASS_ChannelSeconds2Bytes(chan, pos), 0)
    End Function
    Public Shared ReadOnly Property Duration() As Double
        Get
            Return BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetLength(chan, 0))
        End Get
    End Property
    Public Shared ReadOnly Property MaxPosition() As Double
        Get
            Return Duration()
        End Get
    End Property
    Public Shared ReadOnly Property CurrentPosition() As Double
        Get
            Return BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetPosition(chan, 0))
        End Get
       End Property
End Class
<Flags()> _
Enum BASSActive
    Stopped = 0
    Playing = 1
    Stalled = 2
    Paused = 3
End Enum
« Last Edit: 21 Sep '17 - 05:54 by sak2005 »

sak2005

  • Posts: 972
Tip: Run with Process ::)

Example:
Code: [Select]
Public Class Form1
    Private ofd As New OpenFileDialog
    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
            Dim psInfo As New ProcessStartInfo
            psInfo.UseShellExecute = False
            psInfo.FileName = "bplayback"
            psInfo.Arguments = "-loop """ & ofd.FileName & """"
       'OR  psInfo.Arguments = """" & ofd.FileName & """ -loop"
           Process.Start(psInfo)
        End If
    End Sub
End Class
« Last Edit: 21 Sep '17 - 05:57 by sak2005 »

sak2005

  • Posts: 972
Tip: Searching file dlls in the PluginLoad, if not found (debug error!) ::)

Example:
Code: [Select]
public int BASS_PluginLoad(string file)
{
    if (!System.IO.File.Exists(System.IO.Path.Combine(System.Environment.CurrentDirectory, file)))
    {
        string[] items = System.IO.Directory.GetFiles("C:\\", file, System.IO.SearchOption.AllDirectories);
        foreach (var i in items)
        {
            if (i.Contains(file))
            {
               System.IO.File.Copy(i, System.IO.Path.Combine(System.Environment.CurrentDirectory, file));
               break;
            }
        }
    }
    return BASS_PluginLoad(file, -2147483648);
}
« Last Edit: 22 Sep '17 - 17:38 by sak2005 »