Sign in to follow this  
Followers 0
Muchuchu

Simple Question

2 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0