Jump to content

zPlayer - My own little audio/video player


Go to solution Solved by TheXman,

Recommended Posts

Posted
#include <WindowsConstants.au3>

Local $sTitle = "Beethoven - Symphony No.9 in D minor, Op.125 - 'Choral' - 4. Presto Allegro assai.flac"
Local $guiWidth = 400, $aLabel[3], $aWidth[3], $alabelX[3], $iMarqueeInterval = 40
$alabelX[0] = 0
$hGUI = GUICreate("", $guiWidth, 100)
GUISetStyle(-1, BitOR($WS_EX_COMPOSITED, $WS_EX_TOPMOST)) ; $WS_EX_COMPOSITED $WS_EX_TOPMOST
GUISetFont(10, 400, 0, "Arial")
$aLabel[0] = GUICtrlCreateLabel($sTitle, $alabelX[0], 10, -1, 18)
$aWidth[0] = ControlGetPos($hGUI, "", $aLabel[0])[2]
GUISetState()

; Check if the label width exceeds the GUI width
If $aWidth[0] > $guiWidth Then
    $aLabel[1] = GUICtrlCreateLabel("  ðŸŽµ  ", $alabelX[0] + $aWidth[0], 10, -1, 18)
    $aWidth[1] = ControlGetPos($hGUI, "", $aLabel[1])[2]
    $aLabel[2] = GUICtrlCreateLabel($sTitle, $alabelX[1] + $aWidth[1], 10, -1, 18)
    $aWidth[2] = ControlGetPos($hGUI, "", $aLabel[2])[2]
    Sleep(3000)
    AdlibRegister("_Marquee", $iMarqueeInterval)
EndIf


Do
    Sleep(10)
Until GUIGetMsg() = -3
;~ AdlibUnRegister()

Func _Marquee()

    If $alabelX[0] = 0 Then
        $alabelX[1] = $alabelX[0] + $aWidth[0]
        $alabelX[2] = $alabelX[1] + $aWidth[1]
;~      Sleep(3000)
    EndIf

    If $alabelX[2] = 0 Then
        $alabelX[1] = $alabelX[2] + $aWidth[2]
        $alabelX[0] = $alabelX[1] + $aWidth[1]
;~      Sleep(3000)
    EndIf

    $alabelX[0] -= 1
    $alabelX[1] -= 1
    $alabelX[2] -= 1

    ControlMove($hGUI, "", $aLabel[0], $alabelX[0], 10)
    ControlMove($hGUI, "", $aLabel[1], $alabelX[1], 10)
    ControlMove($hGUI, "", $aLabel[2], $alabelX[2], 10)
EndFunc   ;==>_Marquee

 

I know that I know nothing

Posted (edited)

I am happy to report that I have implemented a smooth and infinite marquee for displaying long file names in zPlayer. Below is an exact replica of the code. You can try this code with filenames of different lengths. In this example, the 2nd and 3rd files are both 53 characters long, but their string widths are different: the 2nd is 320 pixels, the same as the GUI, and the 3rd is 340 pixels, slightly wider than the GUI. The first two files do not need to scroll, but the third does.

Global $sTitle, $hGUI, $guiWidth = 320, $idTitle, $titlePosX = 5, $titleWidth
Global $marqueeInterval = 40, $iMarquee, $stopGap = "     ", $titlePosX2

$sTitle = "Luciano Pavarotti - Una Furtiva Lagrima.mp3"             ; 34 characters, 254 pixels
;$sTitle = "Schubert - Symphony No.8 in B minor, 'Unfinished'.mp3"  ; 53 characters, 320 pixels
;$sTitle = "Schumann - Scenes from Childhood, Op 15, Taumerei.mp3"  ; 53 characters, 340 pixels - 'r' intentionally omitted

$hMain = GUICreate("zPlayer", $guiWidth, 100)
GUISetFont(10, 400, 0, "Arial")
$idTitle = GUICtrlCreateLabel($sTitle, $titlePosX, 10, 1000, 18)    ; Initially, make it wide enough
GUISetState()

Local $tmpGUI, $tmpLabel
$tmpGUI = GUICreate("")     ; Temporary GUI to measure pixel width of $sTitle
GUISetFont(10, 400, 0, "Arial", $tmpGUI)
$tmpLabel = GUICtrlCreateLabel($sTitle, 0, 0)
$titleWidth = ControlGetPos($tmpGUI, "", $tmpLabel)[2] - 9  ; The label width is wider than actual string width by 9 pixels.
GUIDelete($tmpGUI)

ConsoleWrite("Title Length:" & @TAB & StringLen($sTitle) & " characters" & @CRLF)
ConsoleWrite("Title Width:" & @TAB & $titleWidth & " pixels" & @CRLF)

If $titleWidth >= $guiWidth - $titlePosX*2 Then
    If $titleWidth <= $guiWidth Then
        ControlMove($hMain, "", $idTitle, Round(($guiWidth-$titleWidth)/2), 10)
    Else
        GUICtrlSetData($idTitle, $sTitle & $stopGap & $sTitle)  ; 5 spaces between tail and trailing head
        $titlePosX2 = $titlePosX
        $iMarquee = 0
        AdlibRegister("_Marquee", $marqueeInterval)
    EndIf
EndIf

Do
    Sleep(10)
Until GUIGetMsg() = -3

Func _Marquee()
    ; 3 seconds of halt when the head comes to the initial position. Sleep() is not recommended.
    $iMarquee += 1
    If $iMarquee < 3000/$marqueeInterval Then Return
    $titlePosX2 -= 1
    ControlMove($hMain, "", $idTitle, $titlePosX2, 10)
    If $titlePosX2 = -$titleWidth - (StringLen($stopGap) * 4 - $titlePosX) Then
        $titlePosX2 = $titlePosX
        $iMarquee = 0
    EndIf
EndFunc


 

Edited by CYCho

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
×
×
  • Create New...