Jump to content

Basic MP3 Player


Donald8282
 Share

Recommended Posts

Hello, Here is a basic MP3 player. I know there are probably a few out there in the forums already.

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <Sound.au3>

GUICreate("Music Player", 300, 140)
GUISetState()

$B_Pause = 0
$B_Play = GUICtrlCreateButton("Play", 10, 90, 70, 25)
$B_Stop = GUICtrlCreateButton("Stop", 90, 90, 70, 25)
GUICtrlSetState($B_Play, $GUI_DISABLE)
GUICtrlSetState($B_Stop, $GUI_DISABLE)

$Menu = GUICtrlCreateMenu("File")
$M_Open = GUICtrlCreateMenuItem("Open", $Menu)
$M_Exit = GUICtrlCreateMenuItem("Exit", $Menu)

$S_SongPosCheck = ""
$S_Name = GUICtrlCreateLabel("", 10, 10, 280, 20)
$S_SongPos = GUICtrlCreateLabel("00:00:00 / 00:00:00", 10, 40, 100, 20)
$S_SongFile = ""

$C_Repeat = GUICtrlCreateCheckbox("Repeat", 200, 93)
GUICtrlSetState($C_Repeat, $GUI_DISABLE)


$Sl_Volume = GUICtrlCreateSlider(10, 60, 280, 20)
GUICtrlSetLimit($Sl_Volume, 100, 0)
GUICtrlSetData($Sl_Volume, 50)
$Sl_VolumeCheck = "50"

While 1
    sleep(10)
    $S_FilePos = _SoundPos($S_SongFile)
    $C_RepeatCheck = GUICtrlRead($C_Repeat)
    $Sl_VolumeNum = GUICtrlRead($Sl_Volume)

    
    If $Sl_VolumeCheck <> $Sl_VolumeNum Then
        TrayTip("", $Sl_VolumeNum, 5)
        SoundSetWaveVolume($Sl_VolumeNum)
        $Sl_VolumeCheck = $Sl_VolumeNum
        TrayTip("", "", 5)
    EndIf
    
    If $S_SongPosCheck <> $S_FilePos Then
        GUICtrlSetData($S_SongPos, _SoundPos($S_SongFile) & " / " & _SoundLength($S_SongFile))
        $S_SongPosCheck = $S_FilePos
    EndIf
    
    If $S_FilePos = _SoundLength($S_SongFile) Then
        If $C_RepeatCheck = $GUI_CHECKED Then
            _SoundStop($S_SongFile)
            _SoundPlay($S_SongFile)
        ElseIf $C_RepeatCheck = $GUI_UNCHECKED And $B_Pause = 1 Then
            GUICtrlSetData($B_Play, "Play")
            $B_Pause = 0
            GUICtrlSetState($B_Stop, $GUI_DISABLE)
            _SoundStop($S_SongFile)
        EndIf
    EndIf
    
    
    
    $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $M_Exit
        Exit
    Case $msg = $M_Open

        GUICtrlSetState($B_Stop, $GUI_DISABLE)
        GUICtrlSetState($C_Repeat, $GUI_DISABLE)
        GUICtrlSetData($B_Play, "Play")
        $B_Pause = 0
        $S_Song = FileOpenDialog("Select an audio file", "", "Sound File (*.wav;*.mp3)", 3)
        $S_SongNameSplit = StringSplit($S_Song, "\")
        $S_SongNameGetSplit = $S_SongNameSplit[0]
        
        If @error Then
            $S_SongNameSplit = ""
            GUICtrlSetData($S_SongPos, "00:00:00 / 00:00:00")
            _SoundStop($S_SongFile)
            _SoundClose($S_SongFile)
        EndIf
        
        If $S_SongNameSplit <> "" Then
            _SoundStop($S_SongFile)
            _SoundClose($S_SongFile)
            GUICtrlSetData($S_Name, $S_SongNameSplit[$S_SongNameGetSplit])
            GUICtrlSetState($B_Play, $GUI_ENABLE)
            $S_SongFile = _SoundOpen($S_Song)
            GUICtrlSetData($S_SongPos, _SoundPos($S_Song) & " / " & _SoundLength($S_SongFile))
        Else
            GUICtrlSetState($B_Play, $GUI_DISABLE)
            GUICtrlSetState($C_Repeat, $GUI_DISABLE)
            GUICtrlSetData($S_Name, "")
            GUICtrlSetData($S_SongPos, "00:00:00 / 00:00:00")
        EndIf
    Case $msg = $B_Play
        If $B_Pause = 0 Then
            GUICtrlSetData($B_Play, "Pause")
            GUICtrlSetState($B_Stop, $GUI_ENABLE)
            GUICtrlSetState($C_Repeat, $GUI_ENABLE)
            _SoundPlay($S_SongFile)
            $B_Pause = 1
        ElseIf $B_Pause = 1 Then
            GUICtrlSetData($B_Play, "Play")
            _SoundPause($S_SongFile)
            $B_Pause = 0
        EndIf
    Case $msg = $B_Stop
        GUICtrlSetState($B_Stop, $GUI_DISABLE)
        GUICtrlSetState($C_Repeat, $GUI_DISABLE)
        GUICtrlSetData($B_Play, "Play")
        $B_Pause = 0
        _SoundStop($S_SongFile)
    EndSelect
WEnd

If you have any problem with the player or find bugs please let me know.

Thanks.

Link to comment
Share on other sites

  • 9 months later...

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...