#๐Ÿ”’ Program Crashing After Playing Sound

25 messages ยท Page 1 of 1 (latest)

north mangoBOT
#

@woeful badge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

woeful badge
#

sigh

#
        open "audio\roll tick.mp3"
    Cannot find the specified file.  Make sure the path and filename are correct.

    Error 263 for command:
        close "audio\roll tick.mp3"
    The specified device is not open or is not recognized by MCI.
Failed to close the file: "audio\roll tick.mp3"
Traceback (most recent call last):
  File "c:\Users\rdama\Downloads\Lems RNG\Lem's RNG.py", line 119, in <module>
    awaitAction()
  File "c:\Users\rdama\Downloads\Lems RNG\Lem's RNG.py", line 95, in awaitAction
    roll()
  File "c:\Users\rdama\Downloads\Lems RNG\Lem's RNG.py", line 52, in roll
    playsound(r"audio\roll tick.mp3")
  File "C:\Users\rdama\AppData\Local\Programs\Python\Python312\Lib\site-packages\playsound.py", line 55, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\rdama\AppData\Local\Programs\Python\Python312\Lib\site-packages\playsound.py", line 50, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
    Error 275 for command:
        open "audio\roll tick.mp3"
    Cannot find the specified file.  Make sure the path and filename are correct.``` here's the error
#

and the script is in the "Lems RNG" folder

#

@pastel coyote

pastel coyote
#

You can check if a file exists with 'os.path.exists(...)'

#

And you installed your library, right?

woeful badge
#

yeah

pastel coyote
#

So it's not running relative to your downloads folder. The lens rng folder is unrelated to what you're running

#

(And you're running a diff version than the code you posted)

woeful badge
#

wait what

pastel coyote
#

The traceback referenced line 55 which didn't correspond to the code you pasted

woeful badge
woeful badge
#

thats all of it

misty lake
#

To always have a path relative to current file's location, as opposed to current working directory, use __file__

Using pathlib you can easily get code file's directory from it:

from pathlib import Path

code_directory = Path(__file__).parent.resolve()

roll_path = code_directory / "audio/roll tick.mp3"
woeful badge
#

ok ty

lunar bay
#

Os.path.join(sys.path[0], filename) if it is in the same folder

#

Thats what i always used

north mangoBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.