Jump to content

Simple Question


Recommended Posts

Trying to make a simple music player just for learning experience. Can\'t seem to get it right. It won\'t do the while statement if I press play even though it seems like i coded it correctly, but I\'m obviously doing something wrong. Here\'s the script.

#include <Sound.au3>

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate(\"Form1\", 255, 81, 439, 140)
global $song = GUICtrlCreateInput(\"\", 80, 8, 153, 21)
$Label1 = GUICtrlCreateLabel(\"Song Name\", 8, 11, 60, 17)
$Play = GUICtrlCreateButton(\"Play\", 48, 40, 65, 33, 0)
$Stop = GUICtrlCreateButton(\"Stop\", 128, 40, 65, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

    
    while 1
$nMsg = GUIGetMsg()
        if $nmsg = $play then
    start()
endif
wend

func start()
    
        Msgbox(1,\"starting\",\"Starting\")
_SoundOpen (\"C:\\Users\\Tim\\Documents\\\" & $song & \".mp3\")
sleep(\"2000\")
_soundplay(\"C:\\Users\\Tim\\Documents\\\" & $song & \".mp3\")
msgbox(1,\"Finished\",\"done\")

endfunc
Edited by Muchuchu
Link to comment
Share on other sites

Trying to make a simple music player just for learning experience. Can\'t seem to get it right. It won\'t do the while statement if I press play even though it seems like i coded it correctly, but I\'m obviously doing something wrong. Here\'s the script.

#include <Sound.au3>

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate(\"Form1\", 255, 81, 439, 140)
global $song = GUICtrlCreateInput(\"\", 80, 8, 153, 21)
$Label1 = GUICtrlCreateLabel(\"Song Name\", 8, 11, 60, 17)
$Play = GUICtrlCreateButton(\"Play\", 48, 40, 65, 33, 0)
$Stop = GUICtrlCreateButton(\"Stop\", 128, 40, 65, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $play
                        start()

    EndSwitch
WEnd

func start()
    
        Msgbox(1,\"starting\",\"Starting\")
_SoundOpen (\"C:\\Users\\Tim\\Documents\\\" & $song & \".mp3\")
sleep(\"2000\")
_soundplay(\"C:\\Users\\Tim\\Documents\\\" & $song & \".mp3\")
msgbox(1,\"Finished\",\"done\")

endfunc
Your problem was the first while loop was never finished so it cannot detect whether you pressed play or not. 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...