TaylorSMarks / playsound

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

Intermittent playback of mp3 issues #77

Closed markstrefford closed 3 years ago

markstrefford commented 3 years ago

I want to use playsound in a Python 3.9 application. I have 3 .mp3 files and note that these play occasionally but not all the time (the same file can work sometimes, and fail others).

For example:

playsound('path_to_audio.mp3')

can return the following error:

Error 265 for command:
        open audio/A-Tone-His_Self-1266414414.mp3
    The device name is already being used as an alias by this application.  Use a unique alias.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Mark\anaconda3\envs\deca\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\Mark\anaconda3\envs\deca\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 265 for command:
        open audio/A-Tone-His_Self-1266414414.mp3
    The device name is already being used as an alias by this application.  Use a unique alias.

When it works, this appears to be the simplest audio player available for cross-platform Python apps, so would be great if this was fixed.

Here's a link to one of my mp3 files:

https://soundbible.com/1815-A-Tone.html

markstrefford commented 3 years ago

Interestingly, this issue also seems to occur if I download the wav files.

For example:

Error playing sound from audio/Robot_blip-Marianne_Gagnon-120342607.wav. Error:
    Error 259 for command:
        play audio/Robot_blip-Marianne_Gagnon-120342607.wav wait
    The driver cannot recognize the specified command parameter.

When I run this in a script, but interactively in the Python shell it is OK?

TaylorSMarks commented 3 years ago

Hi Mark,

Can you update the test.py file with a test case that consistently fails with this issue? The current test suite already plays the same file twice and is working fine, so it must be more complicated than that. Maybe there’s something specific about the file you’re testing with, or the file format, or the name of the file.

It’s difficult to fix a bug when we have no way of knowing how to reliably cause it in the first place.

Bonus points if you can also demonstrate it failing on Travis CI, but I have a Windows 10 laptop I can test on so if it consistently fails for you, it’ll probably fail for me, too.

Thanks, Taylor

Sent from my iPhone

On Jul 27, 2021, at 13:02, Mark Strefford @.***> wrote:

 I want to use playsound in a Python 3.9 application. I have 3 .mp3 files and note that these play occasionally but not all the time (the same file can work sometimes, and fail others).

For example:

playsound('path_to_audio.mp3')

can return the following error:

Error 265 for command: open audio/A-Tone-His_Self-1266414414.mp3 The device name is already being used as an alias by this application. Use a unique alias. Traceback (most recent call last): File "", line 1, in File "C:\Users\Mark\anaconda3\envs\deca\lib\site-packages\playsound.py", line 72, in _playsoundWin winCommand(u'open {}'.format(sound)) File "C:\Users\Mark\anaconda3\envs\deca\lib\site-packages\playsound.py", line 64, in winCommand raise PlaysoundException(exceptionMessage) playsound.PlaysoundException: Error 265 for command: open audio/A-Tone-His_Self-1266414414.mp3 The device name is already being used as an alias by this application. Use a unique alias. When it works, this appears to be the simplest audio player available for cross-platform Python apps, so would be great if this was fixed.

Here's a link to one of my mp3 files:

https://soundbible.com/1815-A-Tone.html

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

markstrefford commented 3 years ago

OK, let me look at that later.

Here's another failing file https://soundbible.com/1682-Robot-Blip.html

markstrefford commented 3 years ago

I don't think this is a repeat play issue.

This file works fine all the time: https://soundbible.com/1815-A-Tone.html This file fails almost every time: https://soundbible.com/1682-Robot-Blip.html but works OK when playing in Windows directly

markstrefford commented 3 years ago

OK, renaming that last file to a shorter filename fixes it

TaylorSMarks commented 3 years ago

I don’t intend for filename length to be a limiting factor, or at least not for filenames that are reasonable (say, shorter than 30 characters?)

Perhaps files with longer names should be automatically renamed by playsound, if this is a real issue with Microsoft’s MCI library…

Sent from my iPhone

On Jul 27, 2021, at 13:30, Mark Strefford @.***> wrote:

 OK, renaming that last file to a shorter filename fixes it

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

markstrefford commented 3 years ago

The filename wasn't that long in my view: audio/Robot_blip-Marianne_Gagnon-120342607.wav Renaming to audio/Robotblip120342607.wav fixed it. I'm on a Windows 11 (Windows Insider) build so not sure if that's caused issues.