Jump to content

Accept Messages while sound is playing?


Recommended Posts

I'm working on a music player. So far, i can get it to load a song, and play a song, and show how far into the song you are. But there is one small problem: My buttons won't return messages when clicked. So if i play a song, the pause button won't work, and the exit button won't work. Can i do this or will i have to stick to another language for the actual playing and stopping?

#include <GUIConstants.au3>
#include <sound.au3>
#NoTrayIcon
Global $pos, $song
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Kenton-Player: Digital Audio Player", 553, 197, 193, 123)
GUISetBkColor(0xA6CAF0)
$Input1 = GUICtrlCreateInput("Browse...", 8, 0, 529, 24)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Browse for Music", 200, 32, 113, 25, 0)
$Button2 = GUICtrlCreateButton("Play", 8, 136, 105, 25, 0)
$Button3 = GUICtrlCreateButton("Pause", 144, 136, 113, 25, 0)
$Button4 = GUICtrlCreateButton("Stop", 288, 136, 113, 25, 0)
$Button5 = GUICtrlCreateButton("Reload", 432, 136, 105, 25, 0)
$Label1 = GUICtrlCreateLabel("Kenton-Player - Digital Audio Player", 160, 72, 216, 20)
$seek = GUICtrlCreateSlider(10, 300)
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $file = FileOpenDialog("Open Music", "C:\", "Music Files (*.mp3)")
            $song = _SoundOpen($file, "current")
            GUICtrlSetData($Input1, $file)
        Case $Button2
            If $song <> "" Then
                _SoundPlay("current")
                Do 
                    GUICtrlSetData($Label1, _SoundPos("current"))
                Until $nMsg = $Button4
            Else
                MsgBox(0, "Error", "No song is selected")
            EndIf
        Case $Button3
        If @Compiled Then
            $CmdLine = '_SoundPause("current")'
            Run( @ScriptFullPath & " /AutoIt3ExecuteLine """ & $CmdLine & """", @ScriptDir, 2)
        Else
            Run( @AutoItExe & " /AutoIt3ExecuteLine """ & $CmdLine & """", @ScriptDir, 2 )
        EndIf
        
    EndSwitch
WEnd
Link to comment
Share on other sites

This should get you going, try to fix it yourself( I am busy making StarCraft map lol).

Things to fix. Stop Button I tidied up a bit so easier to see. Since I am not good at using those func, you need to figure out how to set the sound back to 00:00:00, that's almost all i think. Your problem was you were doing a loop but the msg is not being recieved.

#include <GUIConstants.au3>
#include <sound.au3>
#NoTrayIcon
Global $pos, $song, $inplay
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Kenton-Player: Digital Audio Player", 553, 197, 193, 123)
GUISetBkColor(0xA6CAF0)
$Input1 = GUICtrlCreateInput("Browse...", 8, 0, 529, 24)
GUICtrlSetColor(-1, 0xC0C0C0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("Browse for Music", 200, 32, 113, 25, 0)
$Button2 = GUICtrlCreateButton("Play", 8, 136, 105, 25, 0)
$Button3 = GUICtrlCreateButton("Pause", 144, 136, 113, 25, 0)
$Button4 = GUICtrlCreateButton("Stop", 288, 136, 113, 25, 0)
$Button5 = GUICtrlCreateButton("Reload", 432, 136, 105, 25, 0)
$Label1 = GUICtrlCreateLabel("Kenton-Player - Digital Audio Player", 160, 72, 216, 20)
$seek = GUICtrlCreateSlider(10, 300)
$inplay = False
GUICtrlSetBkColor(-1, 0xA6CAF0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $file = FileOpenDialog("Open Music", "C:\", "Music Files (*.mp3)")
            $song = _SoundOpen($file, "current")
            GUICtrlSetData($Input1, $file)
        Case $Button2
            If $song <> "" Then
                If $inplay = True Then
                    _SoundResume($song)
                    Do
                        $nMsg = GUIGetMsg()
                        GUICtrlSetData($Label1, _SoundPos("current"))
                    Until $nMsg = $Button4 Or $nMsg = $Button3 Or $nMsg = $GUI_EVENT_CLOSE
                    If $nMsg = $Button4 Then
                        _SoundClose($song)
                        _SoundOpen($song)
                        $inplay = Not $inplay
                    ElseIf $nMsg = $Button3 Then
                        _SoundPause($song)
                        $inplay = Not $inplay
                    ElseIf $nMsg = $GUI_EVENT_CLOSE Then
                        Exit
                    EndIf
                ElseIf $inplay= False Then
                    _SoundPlay("current")
                    Do
                        $nMsg = GUIGetMsg()
                        GUICtrlSetData($Label1, _SoundPos("current"))
                    Until $nMsg = $Button4 Or $nMsg = $Button3 Or $nMsg = $GUI_EVENT_CLOSE
                    If $nMsg = $Button4 Then
                        _SoundClose($song)
                        $song = _SoundOpen($file, "current")
                    ElseIf $nMsg = $Button3 Then
                        _SoundPause($song)
                        $inplay = Not $inplay
                    ElseIf $nMsg = $GUI_EVENT_CLOSE Then
                        Exit
                    EndIf
                Else
                    MsgBox(0, "Error", "No song is selected")
                EndIf
            EndIf
            Case $Button3
                If @Compiled Then
                    $CmdLine = '_SoundPause("current")'
                    Run(@ScriptFullPath & " /AutoIt3ExecuteLine """ & $CmdLine & """", @ScriptDir, 2)
                Else
                    Run(@AutoItExe & " /AutoIt3ExecuteLine """ & $CmdLine & """", @ScriptDir, 2)
                EndIf
    EndSwitch
WEnd

Edit: The thing to fix is actually the stop button, also use GUICtrlSetState() to disable the play button while the song is being played.

Edited by Generator
Link to comment
Share on other sites

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