Jetzt hab ich mein erstes kleines ordentliches Programm geschrieben zum Test.
Über Kritik und verbesserungsvorschläge würde ich mich freuen
(und ja ich weiß, mein Sprache ist nicht die beste )
Spoiler anzeigen
; include the UDf for the sound options
#include <Sound.au3>
; User Settings
dim $musicdir = @ScriptDir & "\" ;dir for the music
dim $hotkeyexit = "{ESC}";shortcut for left window
dim $hotkeyvolumeup = "{UP}";shortcut for more volume
dim $hotkeyvolumedown = "{DOWN}";shortcut for less volume
dim $hotkeylasttitel = "{LEFT}";shortcut for last titel
dim $hotkeynexttitel = "{RIGHT}";shortcut for next titel
dim $hotkeyinfo = "^i";shortcut for info tray
Dim $volume = 100;start Volume
SoundSetWaveVolume ($volume);set start Volume
dim $titelAtTime = 1; just at time playing song
;System Settings
dim $sound; object to play music
dim $soundlength; length from song at time
dim $titel = _FileListToArray( $musicdir ,"*.mp3", 1)
;search all mp3 in the folder
Dim $titelnumber = $titel[0];how many songs are ready to play
;Hotkeys for the script
HotKeySet($hotkeyexit, "Terminate")
HotKeySet($hotkeyvolumeup, "volumeup")
HotKeySet($hotkeyvolumedown, "volumedown")
HotKeySet($hotkeylasttitel, "lastTitel")
HotKeySet($hotkeynexttitel, "nextTitel")
HotKeySet($hotkeyinfo, "Info")
; start Player and sound spooler
playsound($titel[$titelAtTime])
soundspooler()
;terminate script
Func Terminate()
_SoundClose($sound)
Exit 0
EndFunc
;function to increase the volume Max Volume = 100
Func volumeup()
if $volume < 90 Then
$volume = $volume + 10
elseif $volume < 100 Then
$volume = 100
EndIf
SoundSetWaveVolume ($volume)
TrayTip ( "Volume", "Wurde auf " & $volume & " erhöht.", 10 )
EndFunc
;function to decrease the volume Min Volume = 0
Func volumedown()
if $volume > 10 Then
$volume = $volume - 10
elseif $volume > 0 Then
$volume = 0
EndIf
SoundSetWaveVolume ($volume)
TrayTip ( "Volume", "Wurde auf " & $volume & " verringert.", 10 )
EndFunc
;function to start the next titel
Func nextTitel()
_SoundClose($sound)
if $titelAtTime < $titelnumber Then
$titelAtTime = $titelAtTime +1
playsound($titel[$titelAtTime])
TrayTip ( "Titel", "Nächster Titel wird gespielt.", 10 )
Else
$titelAtTime = 1
playsound($titel[$titelAtTime])
TrayTip ( "Titel", "Start vom Anfang.", 10 )
EndIf
soundspooler()
EndFunc
;function to start the last titel
Func lastTitel()
_SoundClose($sound)
if $titelAtTime > 1 Then
$titelAtTime = $titelAtTime - 1
playsound($titel[$titelAtTime])
TrayTip ( "Titel", "Letzter Titel wird gespielt.", 10 )
Else
$titelAtTime = $titelnumber
playsound($titel[$titelAtTime])
TrayTip ( "Titel", "Start des letzten Titels.", 10 )
EndIf
soundspooler()
EndFunc
;function to open a sound file and play the music
Func playsound($music)
$sound = _SoundOpen($music)
If @error = 2 Then
MsgBox(0, "Error", "The file does not exist")
Exit
ElseIf @extended <> 0 Then
$extended = @extended ;assign because @extended will be set after DllCall
$stText = DllStructCreate("char[128]")
$errorstring = DllCall("winmm.dll", "short", "mciGetErrorStringA", "str", $extended, "ptr", DllStructGetPtr($stText), "int", 128)
MsgBox(0, "Error", "The open failed." & @CRLF & "Error Number: " & $extended & @CRLF & "Error Description: " & DllStructGetData($stText, 1) & @CRLF & "Please Note: The sound may still play correctly.")
EndIf
_SoundPlay($sound, 0)
EndFunc
;function to show any Information about this song
Func Info()
TrayTip ( "Infos", "Lautstärke: " & $volume & @CRLF & "Derzeitiges Lied:" & $titelAtTime & " von" & $titelnumber & @CRLF & " Liedlänge:" & _SoundLength( $sound, 1 ) & " und die derzeitige Position im Lied " & _SoundPos ( $sound, 1 ), 10 )
EndFunc
;function to start all music
func soundspooler ()
$soundlength = _SoundLength( $sound, 2 )
Sleep($soundlength -_SoundPos ( $sound, 2 ))
nextTitel()
EndFunc