#checking play
1 messages · Page 1 of 1 (latest)
upload the whole file. Use the + to the lift so you don't have to paste it, which takes a lot of vertical space.
@stray dragon let's talk in this thread
ok, give me a few minutes
Thank you. I've been trying to figure this out for 2 weeks so I truly appreciate the help
def play_file(filename):
"""Plays a WAV file in its entirety (function blocks until done)."""
print("Playing", filename)
with open(f"/sounds/{filename}", "rb") as file:
audio.play(audiocore.WaveFile(file))
while audio.playing:
if any(neokey1.get_keys()) or any(neokey2.get_keys()):
audio.stop()
return
change play_file() to the above. How it works:
neokey_something.get_keys() returns a list of True/False values for all the keys, e.g. something like [True, False, False, False]
any() returns True if any of the items in the sequence it is passed is "truthy" (not False or None). So this is checking if any of the buttons are pressed.
If so, then it stops the audio early, and returns immediately.
Then your existing code will check which button is actually pressed and start playing the new sound
Hmmm I'm getting the clicking again
Oh, I know what the problem is, it's that it starts playing right away, and the key is still pressed, so it exits immediately
lemme think about that...
Take your time
quite rewritten. Uses lists of fileanmes and colors. Note how there isn't repeated code
you'll have to test it: I only have one NeoKey
Sure thing one sec
It's rare to write code that works the first time!
Oh I know! (I dabble in ASM for NES dev so I know the feeling
note the + that concatenates the two lists instead of doing an addition, for instance
It’s little things like that man