Jump to content
Sign in to follow this  
Zisly

Error with volume slider

Recommended Posts

Zisly

I'm getting an error when I click on some other windows exept for the player and the player crashes :S

The error say it occurs on line 58 at

$Info = GUIGetCursorInfo()
       While $Info[2] = 1 And $Info[4] = $Slider1
        SoundSetWaveVolume(GUICtrlRead($Slider1))
        ToolTip(GUICtrlRead($Slider1))
        Sleep(100)
        $Info = GUIGetCursorInfo()
    WEnd

The whole code:

$Volume = _SoundGetWaveVolume()
#include <GUIConstants.au3>
#Include <Sound.au3>
Global $mAlias



#region ### START Koda GUI section ### Form=Form1_2.kxf\Form1_2.kxf
$Main = GUICreate("Z Player", 230, 168, 209, 130)
$Pic1 = GUICtrlCreatePic("Data\1.bmp", -8, 0, 237, 167, BitOR($SS_NOPREFIX,$SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSetState($Pic1, $GUI_DISABLE)
$play = GUICtrlCreateButton("(Not allowed)", 80, 16, 67, 32, $BS_BITMAP)
GUICtrlSetImage(-1, "Data\play.bmp", 0)
$stop = GUICtrlCreateButton("(Not allowed)", 16, 48, 67, 32, $BS_BITMAP)
GUICtrlSetImage(-1, "Data\Stop.bmp", 0)
$open = GUICtrlCreateButton("(Not allowed)", 80, 80, 67, 32, $BS_BITMAP)
GUICtrlSetImage(-1, "Data\Open.bmp", 0)
$pause = GUICtrlCreateButton("(Not allowed)", 144, 48, 67, 32, $BS_BITMAP)
GUICtrlSetImage(-1, "Data\Pause.bmp", 0)
$Slider1 = GUICtrlCreateSlider(8, 144, 217, 20, BitOR($TBS_AUTOTICKS,$TBS_BOTH,$TBS_NOTICKS), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetLimit($Slider1, 100, 0);
GUICtrlSetData($Slider1, $Volume)
SoundSetWaveVolume($Volume);
GUISetState()
$Group1 = GUICtrlCreateGroup("Volume", 8, 120, 217, 25, $BS_CENTER, $WS_EX_TRANSPARENT)
GUICtrlSetFont(-1, 13, 800, 0, "MS LineDraw")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### START Koda GUI section ### Form=Form1_2.kxf\Form1_2.kxf

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _SoundStop($mAlias)
            Exit
        Case $open
            Local $music = FileOpenDialog("Choose a file to play", @DesktopDir, "Mp3 Files (*.mp3)", 3)
            If Not @error Then
                _SoundStop($mAlias)
                $mAlias = _SoundOpen($music)
                _SoundPlay($mAlias)
                GUICtrlSetData($play, "Pause")
            Else
                MsgBox(1, "Error", "File could not be loaded/played, please try with another file.")
            EndIf
        Case $play
            _SoundPlay($mAlias)
        Case $stop
            _SoundStop($mAlias)
        Case $pause
            _SoundPause($mAlias)
    EndSwitch
   
    $Info = GUIGetCursorInfo()
       While $Info[2] = 1 And $Info[4] = $Slider1
        SoundSetWaveVolume(GUICtrlRead($Slider1))
        ToolTip(GUICtrlRead($Slider1))
        Sleep(100)
        $Info = GUIGetCursorInfo()
    WEnd
   
    $ggci = GUIGetCursorInfo($Main)
    If $ggci[2] = 0 Then
        ToolTip("")
    EndIf

WEnd


Func _SoundGetWaveVolume();
    Local $WaveVol = -1, $p, $ret
    Const $MMSYSERR_NOERROR = 0
    $p = DllStructCreate("dword");
    If @error Then
        SetError(2);
        Return -2
    EndIf
    $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr($p));
    If ($ret[0] == $MMSYSERR_NOERROR) Then
        $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData($p, 1), 8), 4)) / 0xFFFF * 100);
    Else
        SetError(1);
    EndIf
    $Struct = 0
    Return $WaveVol
EndFunc  ;==>_SoundGetWaveVolume
Exit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×