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

sak2005

  • Posts: 938
Tip: SetVideoWindow in the mciSendString ::)

Example:
Code: [Select]
Public Class Form1
    Public Declare Auto Function mciSendString Lib "winmm.dll" (ByVal pCommand As String, ByVal strBuffer As System.Text.StringBuilder, ByVal bufferSize As Integer, ByVal hWndCallback As IntPtr) As Integer
    Public fDlg As New System.Windows.Forms.OpenFileDialog
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim OpenCommand As String = String.Concat("open """, fDlg.FileName, """ type mpegvideo alias av parent ", Me.Handle, " style child")
            mciSendString(OpenCommand, Nothing, 0, IntPtr.Zero)
            Form1_LocationAndSizeChanged(sender, e)
            Dim PlayCommand As String = "play av"
            mciSendString(PlayCommand, Nothing, 0, IntPtr.Zero)
        End If
    End Sub
    Private Sub Form1_LocationAndSizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged, MyBase.SizeChanged
    Dim SetWindowCommand As String = String.Concat("put av destination at 0 0 ", Me.Width, " ", Me.Height)     
'OR
'Dim SetWindowCommand As String = String.Concat("put av window at 0 0 ", Me.Width, " ", Me.Height)
        mciSendString(SetWindowCommand, Nothing, 0, IntPtr.Zero)
    End Sub
End Class
« Last Edit: 14 Jul '17 - 01:38 by sak2005 »

sak2005

  • Posts: 938
Tip: VC++ VuMeter Function in the mciSound ;D

For parameters , Using by ref is % for progressBar.Value

Example:
Code: [Select]
viod VuMeter(int %vuLeft, int %vuRight )
{
    mciSendString("status capture level", buffer, buffer->Capacity, IntPtr::Zero);
    vuLeft = int.Parse(buffer->ToString()) & 65535;
    vuRight = (int.Parse(buffer->ToString()) >>16) & 65535;
    return;
}

sak2005

  • Posts: 938
Tip: Convert volume max value 1000 to max value 100 ::)

Example:
Code: [Select]
Public Sub Volume(ByVal vol As Integer)
    mciSendString("setaudio sound volume to " & ((1000/100)*vol).ToString(), Nothing, 0, IntPtr.Zero)
    Return
End Sub

sak2005

  • Posts: 938
Tip: Convert Balance max value 1000 to max value 100 ::)

Example:
Code: [Select]
Public Sub Balance(ByVal bal As Integer)
    If (bal > 0) Then
       mciSendString("setaudio sound left volume to " & ((100 - bal) *10).ToString(), Nothing, 0, IntPtr.Zero)
    End Sub             
    If (bal < 0) Then
        mciSendString("setaudio sound right volume to " & ((100 + bal) *10).ToString(), Nothing, 0, IntPtr.Zero)
    End Sub
« Last Edit: 17 Jul '17 - 12:34 by sak2005 »

sak2005

  • Posts: 938
Tip: Info value Volume ::)

Example:
Code: [Select]
If TrackBar1.Value = 0 Then
    Label1.Text = "min"
ElseIf TrackBar1.Value = 50 Then
   Label1.Text = "center"
ElseIf TrackBar1.Value = 100 Then
   Label1.Text = "max"
Else
   Label1.Text = TrackBar1.Value
End If

sak2005

  • Posts: 938
Tip: Info value Balance ::)

Example:
Code: [Select]
If TrackBar2.Value = -100 Then
    Label2.Text = "left"
ElseIf TrackBar2.Value = 0 Then
   Label2.Text = "center"
ElseIf TrackBar2.Value = 100 Then
   Label2.Text = "right"
Else
   Label2.Text = TrackBar2.Value
End If

sak2005

  • Posts: 938
Tip: ReCodes, Learn more about with MS DShow Player ::)

This's converting max value Volume from 4000 to 100, For Volume control and Balance control.

Download: New! DShowLib-2005.dll , Modify add Class dshow control component. Clickhere

Example:
Code: [Select]
private void trackBar1_Scroll(object sender, EventArgs e)
        {
            dShow1.Balance((-4000 / -100) * trackBar1.Value);
            toolTip1.SetToolTip(trackBar1, ((-4000 / -100) * trackBar1.Value).ToString());
        }
       
        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            dShow1.Volume((-4000 / -100) * trackBar2.Value);
            toolTip1.SetToolTip(trackBar2, ((-4000/-100) * trackBar2.Value).ToString());
        }
« Last Edit: 20 Jul '17 - 01:33 by sak2005 »

sak2005

  • Posts: 938
Tip: SetAttributes Volume ::) For mciSendString is maximum volume = 1000

Attributes maximum volume to max value 10 and max value 100

Support VolumeControl and BalanceControl

Code: [Select]
public int SetAttributes(int volValue, int maxValue)
{
    int _value = 0;
    if (maxValue==10)
    {
        _value = (1000 / 100) * volValue * 10;
        volValue = _value;
    }
    else if (maxValue==100)
    {
        _value = (1000 / 100) * volValue;
        volValue = _value;
    }
    else
    {
        if (maxValue==1000)
        {
            _value = (1000 / 1000) * volValue;
            volValue = _value;
        }
    }
    return _value;
}

Example:
Code: [Select]
private void trackBar2_Scroll(object sender, EventArgs e)
{
    pl.Volume(pl.SetAttributes(trackBar2.Value , 100));
}

private void trackBar3_Scroll(object sender, EventArgs e)
{
    pl.Balance(pl.SetAttributes(trackBar3.Value, 100));
}
« Last Edit: 23 Jul '17 - 18:36 by sak2005 »

sak2005

  • Posts: 938
Tip: VLC Player, Without VLC ActiveX ::)

Must add files is libvlc.dll, libvlccore.dll and plugins folder to the debug folder.

Example: Basic VLC
Code: [Select]
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        #region core
        [DllImport("libvlc")]
        private static extern IntPtr libvlc_new(int argc, string[] argv, ref libvlc_exception_t ex);
        [DllImport("libvlc.dll")]
        private static extern void libvlc_release(IntPtr instance);
        #endregion

        #region media
        [DllImport("libvlc")]
        private static extern IntPtr libvlc_media_new(IntPtr p_instance, string psz_mrl, ref libvlc_exception_t p_e);
        [DllImport("libvlc")]
        private static extern void libvlc_media_release(IntPtr p_meta_desc);
        #endregion

        #region player
        [DllImport("libvlc")]
        private static extern IntPtr libvlc_media_player_new_from_media(IntPtr media, ref libvlc_exception_t ex);
        [DllImport("libvlc")]
        private static extern void libvlc_media_player_release(IntPtr player);
        [DllImport("libvlc")]
        private static extern void libvlc_media_player_set_drawable(IntPtr player, IntPtr drawable, ref libvlc_exception_t p_e);
        [DllImport("libvlc")]
        private static extern void libvlc_media_player_play(IntPtr player, ref libvlc_exception_t ex);
        [DllImport("libvlc")]
        private static extern void libvlc_media_player_pause(IntPtr player, ref libvlc_exception_t ex);
        [DllImport("libvlc")]
        private static extern void libvlc_media_player_stop(IntPtr player, ref libvlc_exception_t ex);
        [DllImport("libvlc")]
        private static extern PlayerState libvlc_media_player_get_state(IntPtr player, ref libvlc_exception_t ex);
        #endregion

        #region exception
        [DllImport("libvlc")]
        public static extern void libvlc_exception_init(ref libvlc_exception_t p_exception);
        [DllImport("libvlc")]
        public static extern int libvlc_exception_raised(ref libvlc_exception_t p_exception);
        [DllImport("libvlc")]
        public static extern string libvlc_exception_get_message(ref libvlc_exception_t p_exception);
        #endregion

        #region constructors
        OpenFileDialog fDlg;
        Timer time;
        public libvlc_exception_t ex;
        public IntPtr instant;
        public IntPtr media;
        public IntPtr player;
        public string file;
        public Form1(): base()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            this.MaximizeBox = false;
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            InitializeComponent();
            panel1.BackColor = System.Drawing.Color.Black;
            time = new Timer();
            fDlg = new OpenFileDialog();
            ex = new libvlc_exception_t();
            instant = IntPtr.Zero;
            media = IntPtr.Zero;
            player = IntPtr.Zero;
            file = string.Empty;
            time.Tick += new EventHandler(time_Tick);
        }
        #endregion

        #region methods
        public void VlcInit()
        {
            //Loading plugin dlls in the plugins folder.
            string[] args = new string[] { "-I", "dummy", "--ignore-config", "--plugin-path", "--vout-filter=deinterlace", "--deinterlace-mode=blend" };
            instant = libvlc_new(args.Length, args, ref ex);
            Raise(ref ex);
            ex = new libvlc_exception_t();
            libvlc_exception_init(ref ex);
        }
        public void LoadMedia(string strFile, IntPtr Window)
        {
            //Streamfree.
            if (file != string.Empty) {Close(); }
            file = strFile;
            //Open media file.
            media = libvlc_media_new(instant, file, ref ex);
            Raise(ref ex);
            player = libvlc_media_player_new_from_media(media, ref ex);
            Raise(ref ex);
            libvlc_media_release(media);
            //Set VideoWindow. Note: If mouse doubleClick to fullscreen.
            libvlc_media_player_set_drawable(player, Window, ref ex);
            Raise(ref ex);
        }
        public void Play()
        {
            if (media == IntPtr.Zero && player == IntPtr.Zero) { return; }
            libvlc_media_player_play(player, ref ex);
            Raise(ref ex);
        }
        public void Pause()
        {
            if (media == IntPtr.Zero && player == IntPtr.Zero) { return; }
            libvlc_media_player_pause(player, ref ex);
            Raise(ref ex);
        }
        public void Stop()
        {
            if (media == IntPtr.Zero && player == IntPtr.Zero) { return; }
            libvlc_media_player_stop(player, ref ex);
            Raise(ref ex);
        }
        public void Close()
        {
            if (media == IntPtr.Zero && player == IntPtr.Zero) { return; }
            try
            { libvlc_media_player_release(player); }
            catch
            { libvlc_media_release(media); }
        }
        public PlayerState State
        {
            get
            {
                return libvlc_media_player_get_state(player, ref ex);
                Raise(ref ex);
            }
        }
        public void Raise(ref libvlc_exception_t ex)
        {
            if (libvlc_exception_raised(ref ex) != 0)
            {
                MessageBox.Show(libvlc_exception_get_message(ref ex));
            }
        }
        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            VlcInit();
        }
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (fDlg.ShowDialog() == DialogResult.OK)
            {
                this.Text = fDlg.SafeFileName;
                LoadMedia(fDlg.FileName, panel1.Handle);
                btnPlay_Click(sender, e);
            }
        }
        private void btnPlay_Click(object sender, EventArgs e)
        {
           Play();
           time.Start();
        }
       
        private void btnPause_Click(object sender, EventArgs e)
        {
           Pause();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
           Stop();
        }
        private void time_Tick(object sender, EventArgs e)
        {
            //Sync state stopped.
            if (State == PlayerState.stopped){btnStop_Click(sender, e);}
        }
    }

    #region struct exception
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct libvlc_exception_t
    {
        public int b_raised;
        public int i_code;
        public string psz_message;
    }
    #endregion

    #region enum state
    public enum PlayerState : int
    {
        waiting,
        ready,
        opening,
        buffering,
        playing,
        paused,
        stopped,
        ended,
        error
    }
    #endregion
}


« Last Edit: 26 Jul '17 - 12:02 by sak2005 »

sak2005

  • Posts: 938
VLC Player.Net Sample: ;D
Code: [Select]
Public Class Form1
#Region "core"
    Private Declare Function libvlc_new Lib "libvlc" (ByVal argc As Integer, ByVal argv As String(), ByRef ex As libvlc_exception_t) As IntPtr
    Private Declare Sub libvlc_release Lib "libvlc" (ByVal instance As IntPtr)
#End Region

#Region "media"
    Private Declare Function libvlc_media_new Lib "libvlc" (ByVal player As IntPtr, ByVal file As String, ByRef ex As libvlc_exception_t) As IntPtr
    Private Declare Sub libvlc_media_release Lib "libvlc" (ByVal p_meta_desc As IntPtr)
#End Region

#Region "player"
    Private Declare Function libvlc_media_player_new_from_media Lib "libvlc" (ByVal media As IntPtr, ByRef ex As libvlc_exception_t) As IntPtr
    Private Declare Sub libvlc_media_player_release Lib "libvlc" (ByVal player As IntPtr)
    Private Declare Sub libvlc_media_player_set_drawable Lib "libvlc" (ByVal player As IntPtr, ByVal drawable As IntPtr, ByRef ex As libvlc_exception_t)
    Private Declare Sub libvlc_media_player_play Lib "libvlc" (ByVal player As IntPtr, ByRef ex As libvlc_exception_t)
    Private Declare Sub libvlc_media_player_pause Lib "libvlc" (ByVal player As IntPtr, ByRef ex As libvlc_exception_t)
    Private Declare Sub libvlc_media_player_stop Lib "libvlc" (ByVal player As IntPtr, ByRef ex As libvlc_exception_t)
    Private Declare Function libvlc_media_player_get_state Lib "libvlc" (ByVal player As IntPtr, ByRef ex As libvlc_exception_t) As PlayerState
#End Region

#Region "exceptions"
    Private Declare Sub libvlc_exception_init Lib "libvlc" (ByRef ex As libvlc_exception_t)
    Private Declare Function libvlc_exception_raised Lib "libvlc" (ByRef ex As libvlc_exception_t) As Integer
    Private Declare Function libvlc_exception_get_message Lib "libvlc" (ByRef ex As libvlc_exception_t) As String
#End Region

#Region "constructors"
    Private fDlg As OpenFileDialog
    Private time As System.Windows.Forms.Timer
    Public ex As libvlc_exception_t
    Public instant As IntPtr
    Public media As IntPtr
    Public player As IntPtr
    Public file As String
    Public Sub New()
        MyBase.New()
        Me.StartPosition = FormStartPosition.CenterScreen
        Me.MaximizeBox = False
        Me.AutoSizeMode = AutoSizeMode.GrowAndShrink
        InitializeComponent()
        Panel1.BackColor = System.Drawing.Color.Black
        time = New System.Windows.Forms.Timer
        fDlg = New OpenFileDialog
        ex = New libvlc_exception_t
        instant = IntPtr.Zero
        media = IntPtr.Zero
        player = IntPtr.Zero
        file = String.Empty
        AddHandler time.Tick, AddressOf time_Tick
    End Sub
#End Region

#Region "methods"
    Public Sub VlcInit()
        'Loading plugin dlls in the plugins folder.
        Dim args As String() = New String() {"-I", "dummy", "--ignore-config", "--plugin-path", "--vout-filter=deinterlace", "--deinterlace-mode=blend"}
        instant = libvlc_new(args.Length, args, ex)
        Raise(ex)
        ex = New libvlc_exception_t
        libvlc_exception_init(ex)
    End Sub
    Public Sub LoadMedia(ByVal strFile As String, ByVal Window As IntPtr)
        'Streamfree.
        If file <> String.Empty Then [Close]()
        file = strFile
        'Open media file.
        media = libvlc_media_new(instant, file, ex)
        Raise(ex)
        player = libvlc_media_player_new_from_media(media, ex)
        Raise(ex)
        libvlc_media_release(media)
        'Set VideoWindow. Note: If mouse doubleClick to fullscreen.
        libvlc_media_player_set_drawable(player, Window, ex)
        Raise(ex)
    End Sub
    Public Sub Play()
        If media = IntPtr.Zero AndAlso player = IntPtr.Zero Then Return
        libvlc_media_player_play(player, ex)
        Raise(ex)
    End Sub
    Public Sub Pause()
        If media = IntPtr.Zero AndAlso player = IntPtr.Zero Then Return
        libvlc_media_player_pause(player, ex)
        Raise(ex)
    End Sub
    Public Sub [Stop]()
        If media = IntPtr.Zero AndAlso player = IntPtr.Zero Then Return
        libvlc_media_player_stop(player, ex)
        Raise(ex)
    End Sub
    Public Shadows Sub [Close]()
        If media = IntPtr.Zero AndAlso player = IntPtr.Zero Then Return
        Try
            libvlc_media_player_release(player)
        Catch
            libvlc_media_release(media)
        End Try
    End Sub
    Public ReadOnly Property State() As PlayerState
        Get
            Return libvlc_media_player_get_state(player, ex)
            Raise(ex)
        End Get
    End Property
    Public Sub Raise(ByRef ex As libvlc_exception_t)
        If libvlc_exception_raised(ex) <> 0 Then
            MessageBox.Show(libvlc_exception_get_message(ex))
        End If
    End Sub
#End Region

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        VlcInit()
    End Sub
    Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        If fDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.Text = fDlg.SafeFileName
            LoadMedia(fDlg.FileName, Panel1.Handle)
            btnPlay_Click(sender, e)
        End If
    End Sub
    Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Play()
        time.Start()
    End Sub

    Private Sub btnPause_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Pause()
    End Sub
    Private Sub btnStop_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        [Stop]()
    End Sub
    Private Sub time_Tick(ByVal sender As Object, ByVal e As EventArgs)
        'Sync state stopped.
        If State = PlayerState.stopped Then btnStop_Click(sender, e)
    End Sub
End Class

#Region "struct exceptions"
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential, CharSet:=Runtime.InteropServices.CharSet.Auto, Pack:=1)> _
Public Structure libvlc_exception_t
    Public b_raised As Integer
    Public i_code As Integer
    Public psz_message As String
End Structure
#End Region

#Region "enum state"
Public Enum PlayerState As Integer
    waiting
    ready
    opening
    buffering
    playing
    paused
    stopped
    ended
    [error]
End Enum
#End Region
« Last Edit: 26 Jul '17 - 15:21 by sak2005 »