Jump to content

Is there anything like a "time" bar control in AutoIt?


 Share

Recommended Posts

I'm talking about the one media players usually have, which tells you at which point inside the media file you're playing you are. You can usually "move around" in the media file by clicking on it.

For example, this is VLC's. http://puu.sh/i8CXK/ad9f3b5b0b.png http://puu.sh/i8D4j/81243541a8.png

Is there a control like that in AutoIt, or should it be custom made?

E: if there isn't, what should I look at for a good start?

Edited by Khryus

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

  • Moderators

Khryus,

It is called a Progress bar - GUICtrlCreateProgress is the function to check in the Help file.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Khryus,

It is called a Progress bar - GUICtrlCreateProgress is the function to check in the Help file.

M23

​Hey, thanks for the reply. 

I don't want to sound rude, but I already knew about this control, however I didn't want to mention it because it was very different from what I'm looking for (infact I was leaning more towards the slider control) and hence thought I had to look at something else. I gave a look at the styles and extended styles of the progress bar, but I didn't find anything that could be useful to me (or at least I think so). I don't have much experience, so bear with me please - what should I be looking for here? I'm not asking for code - I'd just like some tips on how to go about this =)

Edited by Khryus

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

  • Moderators

Khryus,

The image you posted is just a simple progress bar with elapsed and total times displayed in labels at each end. As to adjusting the playing point, in the music player I wrote and use all the time I look for a click on the progress bar and then display a slider to allow me to move around within the song.  Give me a while and I will try and come up with something which shows how I went about it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Khryus,

The image you posted is just a simple progress bar with elapsed and total times displayed in labels at each end. As to adjusting the playing point, in the music player I wrote and use all the time I look for a click on the progress bar and then display a slider to allow me to move around within the song.  Give me a while and I will try and come up with something which shows how I went about it.

M23

​Thank you very much - the problem weren't the labels, but the slider. I'll keep working on the rest of the interface of my program. Thanks a lot ! :D 

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

  • Moderators

Khtyus,

Take a look at this. The buttons are self-explanatory - click on the progress to allow you to vary the position:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SliderConstants.au3>
#include <ProgressConstants.au3>
#include <ScrollbarConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>

Global $bPlay = False
Global $bSeek = False
Global $iDuration = 100
Global $iElapsed = 0
Global $iCurrent_Progress

$hGUI = GUICreate("Test", 500, 500)

$cProgress = GUICtrlCreateProgress(100, 10, 280, 20)

$cSlider = GUICtrlCreateSlider(100, 100, 280, 20, BitOR($TBS_BOTH, $TBS_NOTICKS))
GUICtrlSetState($cSlider, $GUI_HIDE)
$hSlider = GUICtrlGetHandle($cSlider)

$cLabel_Elapsed = GUICtrlCreateLabel($iElapsed, 10, 10, 80, 20, $SS_CENTER)
$cLabel_Total = GUICtrlCreateLabel($iDuration, 400, 10, 80, 20, $SS_CENTER)

$cPlayPause = GUICtrlCreateButton("Play", 100, 200, 80, 30)
$cReset = GUICtrlCreateButton("Reset", 300, 200, 80, 30)

GUISetState()

GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL")

$nBegin = TimerInit()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cPlayPause

            Switch GUICtrlRead($cPlayPause)
                Case "Play"
                    GUICtrlSetData($cPlayPause, "Pause")
                    $bPlay = True
                    ; Progress to green
                    GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 1, 0)
                Case "Pause"
                    GUICtrlSetData($cPlayPause, "Play")
                    $bPlay = False
                    ; Progress to yellow
                    GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 3, 0)
            EndSwitch

        Case $cReset

            $iElapsed = 0
            GUICtrlSetData($cProgress, 0)
            GUICtrlSetData($cSlider, 0)
            GUICtrlSetData($cLabel_Elapsed, "00")
        Case $GUI_EVENT_PRIMARYDOWN
            $aInfo = GUIGetCursorInfo($hGUI)
            If $aInfo[4] = $cProgress Then
                ; Pause
                GUICtrlSetData($cPlayPause, "Play")
                $bPlay = False
                ; Show Slider
                GUICtrlSetState($cSlider, $GUI_SHOW)
                ; Progress to red
                GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 2, 0)
            EndIf

    EndSwitch



    If TimerDiff($nBegin) > 1000 Then
        If $bPlay Then
            $iElapsed += 1
            GUICtrlSetData($cProgress, $iElapsed)
            GUICtrlSetData($cSlider, $iElapsed)
            GUICtrlSetData($cLabel_Elapsed, $iElapsed)
        EndIf

        $nBegin = TimerInit()
    EndIf

WEnd



Func Start_Seek()

    ; Set seek flag
    $bSeek = True

    ; Pause and mark position
    $bPlay = False
    GUICtrlSetData($cPlayPause, "Play")
    $iCurrent_Progress = GUICtrlRead($cProgress)

    ; Show slider
    GUICtrlSetState($cSlider, $GUI_SHOW)

EndFunc   ;==>Start_Seek

Func End_Seek()

    ; Read slider
    Local $iSeek_Pos = GUICtrlRead($cSlider)

    ; If within 2% resume, else set and play
    If Abs($iSeek_Pos - $iCurrent_Progress) < 2 Then
        $bPlay = True
    Else
        GUICtrlSetData($cProgress, $iSeek_Pos)
        GUICtrlSetData($cLabel_Elapsed, $iSeek_Pos)
        $iElapsed = $iSeek_Pos

    EndIf



    ; Progress to green
    GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 1, 0)

    ; Hide slider
    GUICtrlSetState($cSlider, $GUI_HIDE)

    ; Reset seek flag
    $bSeek = False

    ; Restart playing
    $bPlay = True

EndFunc   ;==>End_Seek

Func _WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg



    If $lParam = $hSlider Then
        If _WinAPI_LoWord($wParam) = $SB_THUMBTRACK Then
            If $bSeek = False Then Start_Seek()
            GUICtrlSetData($cLabel_Elapsed, GUICtrlRead($cSlider))
        Else
            If $bSeek = True Then End_Seek()
        EndIf

    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_HSCROLL

Please ask if you have any questions.


M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here's a variation of the way I do it on my media player (we all have one of these don't we?).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SliderConstants.au3>
#include <ProgressConstants.au3>
#include <ScrollbarConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>

Global $bPlay = False
Global $bSeek = False
Global $iDuration = 100
Global $iElapsed = 0
Global $iCurrent_Progress

$hGUI = GUICreate("Test", 500, 500)

$cLabelProgress = GUICtrlCreateLabel("", 100, 10, 280, 20) ; cover the location of the progress bar with a label to register clicks
$cProgress = GUICtrlCreateProgress(100, 10, 280, 20)
$cLabel_Elapsed = GUICtrlCreateLabel($iElapsed, 10, 10, 80, 20, $SS_CENTER)
$cLabel_Total = GUICtrlCreateLabel($iDuration, 400, 10, 80, 20, $SS_CENTER)

$cPlayPause = GUICtrlCreateButton("Play", 100, 200, 80, 30)
$cReset = GUICtrlCreateButton("Reset", 300, 200, 80, 30)

GUISetState()

$nBegin = TimerInit()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cPlayPause

            Switch GUICtrlRead($cPlayPause)
                Case "Play"
                    GUICtrlSetData($cPlayPause, "Pause")
                    $bPlay = True
                    ; Progress to green
                    GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 1, 0)
                Case "Pause"
                    GUICtrlSetData($cPlayPause, "Play")
                    $bPlay = False
                    ; Progress to yellow
                    GUICtrlSendMsg($cProgress, $PBM_SETSTATE, 3, 0)
            EndSwitch

        Case $cReset
            $iElapsed = 0
            GUICtrlSetData($cProgress, 0)
            GUICtrlSetData($cSlider, 0)
            GUICtrlSetData($cLabel_Elapsed, "00")
        Case $cLabelProgress
            $aInfo = GUIGetCursorInfo($hGUI)
            GUICtrlSetData($cPlayPause, "Play")
            $iMouseClickPosition = $aInfo[0] - 100 ;subtract the starting location of the progress bar
            $ProgressPosition = Round(($iMouseClickPosition / 280) * 100) ; find the percentage of the bar position click location
            GUICtrlSetData($cProgress, $ProgressPosition) ; set the progress bar
            $iElapsed = $ProgressPosition ; update the elapsed time
    EndSwitch

    If TimerDiff($nBegin) > 1000 Then
        If $bPlay Then
            $iElapsed += 1
            GUICtrlSetData($cProgress, $iElapsed)
            GUICtrlSetData($cSlider, $iElapsed)
            GUICtrlSetData($cLabel_Elapsed, $iElapsed)
        EndIf

        $nBegin = TimerInit()
    EndIf

WEnd

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you guys, I'll check it ASAP. Got a little too much into the interface (I work slowly x.x) and forgot to check back. I'll study your code carefully and hopefully if I have any questions, and if it isn't too much of an hassle, you guys can answer me :)

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...