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
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <ProgressConstants.au3>
Opt("TrayMenuMode", 1)
;erstelle GUI
Global $sound
GUICreate("Sound Player", 220, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, Default, $WS_EX_ACCEPTFILES)
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)
$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
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
WEnd
[/autoit] [autoit][/autoit] [autoit]Func NewSound()
If $count > 0 Then
_SoundClose($sound)
EndIf
$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
Func Drop()
If $count > 0 Then
_SoundClose($sound)
EndIf
$sound = _SoundOpen(@GUI_DragFile, "Musik")
_SoundPlay($sound)
$count = $count + 1
EndFunc ;==>Drop
Func Stop()
If $stopcounter = 0 Then
_SoundPause($sound)
GUICtrlSetData($stop, "Fortsetzen")
$stopcounter = 1
Else
_SoundResume($sound)
GUICtrlSetData($stop, "Anhalten")
$stopcounter = 0
EndIf
EndFunc ;==>Stop
Func Weiter()
_SoundResume($sound)
EndFunc ;==>Weiter
Func Lautstarke()
$vol = GUICtrlRead($Slider1)
SoundSetWaveVolume($vol)
EndFunc ;==>Lautstarke
Func e()
For $i = 255 To 1 Step -1
WinSetTrans("Sound Player", "", $i)
Next
Exit
EndFunc ;==>e
Func v()
WinSetState("Sound Player", "", @SW_HIDE)
EndFunc ;==>v
Func iv()
WinSetState("Sound Player", "", @SW_SHOW)
EndFunc ;==>iv
Func min()
WinSetState("Sound Player", "", @SW_MINIMIZE)
EndFunc ;==>min
Func norm()
WinSetState("Sound Player", "", @SW_RESTORE)
EndFunc ;==>norm
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