I want my program do something along the lines of:
while this program is running:
if the Enter
key is pressed, stop the current music file playing.
Here is my code:
# https://docs.python.org/2/library/winsound.html
from msvcrt import getch
import winsound
while True:
key = ord(getch())
if key == 13:
winsound.PlaySound(None, winsound.SND_NOWAIT)
winsound.PlaySound("SystemAsterisk", winsound.SND_ALIAS)
winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
winsound.PlaySound("SystemHand", winsound.SND_ALIAS)
winsound.PlaySound("SystemQuestion", winsound.SND_ALIAS)
winsound.MessageBeep()
winsound.PlaySound('C:/Users/Admin/My Documents/tone.wav', winsound.SND_FILENAME)
winsound.PlaySound("SystemAsterisk", winsound.SND_ALIAS)
In the documentation (see link in the first line of my code), I am unsure weather winsound.SND_NOWAIT
can be used like this: winsound.SND_NOWAIT()
, or like how I tried to use it in my code under the if
statement, or if both statements produce the same effect.
It is my understanding that the program will never get to play the sound files until after I press the Enter
button, as the getch()
part requires before continuing.
However, even if that part of the code does not care when I press anything, wouldn't the program get stuck in the while
loop?