Closed FoamyGuy closed 2 years ago
I think it may be good to merge #116 to fix this. That PR was already implementing similar behavior by adding a stop_play()
function which does close the file. Afterwards it could also close the file at the beginning of play_file()
if It's still open.
resolved by #116
In the currently released version of this library calling
pyportal.peripherals.play_file("somefile.wav", wait_to_finish=False)
results in no audio playing.Full reproducer script:
Running the same code on version
6.0.0
of this library does play the wav file.I think the change to use
with
context processor is what is causing it not to play the file whenwait_to_finish
isFalse
In this section of code it returns in the case of
False
forwait_to_finish
the return causes it to close thewith
context which closes the file and causes it not to be able to be played.https://github.com/adafruit/Adafruit_CircuitPython_PyPortal/blob/a160fd188a66e0f91f445e899a9a38876700a541/adafruit_pyportal/peripherals.py#L149-L157
Unless there is some way to make the lifetime of the
with
block continue to remain open after theplay_file()
function returns I think we would need to remove the usage of thewith
. We could store the reference to the open file onself
and close it on subsequent calls before opening a new one.