TaylorSMarks / playsound

Pure Python, cross platform, single function module with no dependencies for playing sounds.
Other
504 stars 118 forks source link

Fixed playback on Windows with block=false #110

Open t1nky opened 2 years ago

t1nky commented 2 years ago

Fixed playback on Windows with block=false

TaylorSMarks commented 2 years ago

How much have you tested this?

Do you have a test case where the code previously reliably failed but this now reliably works?

One possible issue I see here is that if you call it a second time while the first sound is still playing, it would close the sound… what happens then? Does playback immediately stop, or is an exception thrown? Both? Neither? Does it put MCI into a bad state where you can’t call it again afterwards?

t1nky commented 2 years ago

How much have you tested this?

Couple cases, total 20-30 minutes:

# The first playback stops after sleep, then the second playback starts
import time
from playsound import playsound

playsound('./audio/notification.mp3', block=False)
time.sleep(0.1)
playsound('./audio/notification.mp3', block=False)

time.sleep(0.5)
# The first playback stops after sleep
import time
from playsound import playsound

playsound('./audio/notification.mp3', block=False)
time.sleep(0.1)
# The first playback starts and then stops immediately 
import time
from playsound import playsound

playsound('./audio/notification.mp3', block=False)
# tested for 10 minutes on a 25KB file, was still playing after 10 minutes and memory usage did not increase
import time
from playsound import playsound

while True:
  playsound('./audio/notification.mp3', block=False)
  time.sleep(0.01)

Do you have a test case where the code previously reliably failed but this now reliably works?

Check the first case above, does not work for me (Windows 10 Pro 10.0.19044). Fix does not produce exceptions or new debug logs and works, file is being played successfully.

One possible issue I see here is that if you call it a second time while the first sound is still playing, it would close the sound… what happens then? Does playback immediately stop, or is an exception thrown? Both? Neither? Does it put MCI into a bad state where you can’t call it again afterwards?

Playback stops, no exceptions, MCI is fine I guess, I've re-opened and ran the above tests multiple times, I think if there was some issue with MCI I'd see it right away.

TheBoojah commented 1 year ago

Thanks @t1nky, this worked for me on win 10.