Soundlänge aktualisieren

  • Hallo,

    ich habe hier ein Mini-Sound-Player und würde gerne die Soundposition und die Soundlänge mit einem Label anzeigen lassen und das Label jede Sekunde updaten. Leider klappt das nicht! ;( Ich habe es mit AdlibEnable versucht (die Funktion heißt "Update").
    Könnt ihr euch das Script vielleicht mal ansehen?

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <WindowsConstants.au3>
    #include <Sound.au3>
    #include <ProgressConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("TrayMenuMode", 1)
    ;erstelle GUI
    Global $sound
    GUICreate("Sound Player", 220, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, Default, $WS_EX_ACCEPTFILES)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetIcon(@SystemDir & "\shell32.dll", "-169")

    [/autoit] [autoit][/autoit] [autoit]

    TraySetIcon(@SystemDir & "\shell32.dll", "-169")

    [/autoit] [autoit][/autoit] [autoit]

    $LeerLabel = GUICtrlCreateLabel('', 0, 0, 220, 90)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $fortschritt = GUICtrlCreateLabel('0:0/0:0', 90, 90, 220, 90)

    [/autoit] [autoit][/autoit] [autoit]

    $Slider1 = GUICtrlCreateSlider(10, 10, 200, 30, BitOR($TBS_TOOLTIPS, $TBS_AUTOTICKS))
    $btn = GUICtrlCreateButton("Dateiauswahl", 10, 50, 100, 30)
    $stop = GUICtrlCreateButton("Anhalten", 110, 50, 100, 30)
    GUICtrlSetData($Slider1, 50)
    GUISetState(@SW_SHOW)
    $count = 0
    $stopcounter = 0
    ;GUI Ende
    ;erstelle Traymenü
    $stopitem = TrayCreateItem("Anhalten")
    $fortitem = TrayCreateItem("Fortsetzen")
    $datitem = TrayCreateItem("Dateiauswahl")
    TrayCreateItem("")
    $invisibleitem = TrayCreateItem("Unsichtbar")
    $visibleitem = TrayCreateItem("Sichtbar")
    TrayCreateItem("")
    $minitem = TrayCreateItem("Minimieren")
    $normitem = TrayCreateItem("Wiederherstellen")
    TrayCreateItem("")
    $exititem = TrayCreateItem("Beenden")
    ;Traymenü Ende

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    e()
    Case $btn
    NewSound()
    Case $stop
    Stop()
    Case $Slider1
    Lautstarke()
    Case $GUI_EVENT_DROPPED
    Drop()
    EndSwitch
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $datitem
    NewSound()
    Case $msg = $stopitem
    Stop()
    Case $msg = $fortitem
    Weiter()
    Case $msg = $visibleitem
    iv()
    Case $msg = $invisibleitem
    v()
    Case $msg = $exititem
    e()
    Case $msg = $minitem
    min()
    Case $msg = $normitem
    norm()
    EndSelect

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func NewSound()
    If $count > 0 Then
    _SoundClose($sound)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $var = FileOpenDialog("Bitte wählen Sie eine Sounddatei aus!", "C:\", "Musik (*.mp3;*.wma;*.wav;*.mid)", 1 + 4)
    $sound = _SoundOpen($var, "Musik")
    $count = $count + 1
    _SoundPlay($sound)
    AdlibEnable("Update", 1000)
    EndFunc ;==>NewSound

    [/autoit] [autoit][/autoit] [autoit]

    Func Drop()
    If $count > 0 Then
    _SoundClose($sound)
    EndIf
    $sound = _SoundOpen(@GUI_DragFile, "Musik")
    _SoundPlay($sound)
    $count = $count + 1
    EndFunc ;==>Drop

    [/autoit] [autoit][/autoit] [autoit]

    Func Stop()
    If $stopcounter = 0 Then
    _SoundPause($sound)
    GUICtrlSetData($stop, "Fortsetzen")
    $stopcounter = 1
    Else
    _SoundResume($sound)
    GUICtrlSetData($stop, "Anhalten")
    $stopcounter = 0
    EndIf
    EndFunc ;==>Stop

    [/autoit] [autoit][/autoit] [autoit]

    Func Weiter()
    _SoundResume($sound)
    EndFunc ;==>Weiter

    [/autoit] [autoit][/autoit] [autoit]

    Func Lautstarke()
    $vol = GUICtrlRead($Slider1)
    SoundSetWaveVolume($vol)
    EndFunc ;==>Lautstarke

    [/autoit] [autoit][/autoit] [autoit]

    Func e()
    For $i = 255 To 1 Step -1
    WinSetTrans("Sound Player", "", $i)
    Next
    Exit
    EndFunc ;==>e

    [/autoit] [autoit][/autoit] [autoit]

    Func v()
    WinSetState("Sound Player", "", @SW_HIDE)
    EndFunc ;==>v

    [/autoit] [autoit][/autoit] [autoit]

    Func iv()
    WinSetState("Sound Player", "", @SW_SHOW)
    EndFunc ;==>iv

    [/autoit] [autoit][/autoit] [autoit]

    Func min()
    WinSetState("Sound Player", "", @SW_MINIMIZE)
    EndFunc ;==>min

    [/autoit] [autoit][/autoit] [autoit]

    Func norm()
    WinSetState("Sound Player", "", @SW_RESTORE)
    EndFunc ;==>norm

    [/autoit] [autoit][/autoit] [autoit]

    Func Update()
    $z = _SoundPos("Musik", 0) ;Aktuelle Position
    $d = _SoundLength("Musik", 0) ;Soundlänge
    GUICtrlSetData($fortschritt, _SoundPos("Musik"))
    If $z = $d Then
    AdlibDisable()
    EndIf
    EndFunc ;==>Update

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Einmal editiert, zuletzt von xp_fan (21. November 2009 um 14:11)

  • Jetzt sollte es klappen :D

    [autoit]

    AdlibEnable("update")

    [/autoit][autoit][/autoit][autoit]

    Func Update()
    $z = _SoundPos($sound, 1)
    $d = _SoundLength($sound, 1)
    GUICtrlSetData($fortschritt, $z)
    EndFunc ;==>Update

    [/autoit]

    Deine Fehler: Dum mußt bei den Sound-Funktionen die Sound ID verwenden 8o