Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed playback on Windows with block=false #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

t1nky
Copy link

@t1nky t1nky commented Feb 3, 2022

Fixed playback on Windows with block=false

Fixed playback on Windows with block=false
@t1nky t1nky changed the title Update playsound.py Fixed playback on Windows with block=false Feb 3, 2022
@TaylorSMarks
Copy link
Owner

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
Copy link
Author

t1nky commented Feb 3, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants