Search code examples
pythonaudiopyglet

pyglet only play sound from same directory


So i have this piece of code which will play a sound but it only works if it is in the same directory

# Doesnt work
current_directory = os.getcwd()
path = os.path.join(current_directory + "\sounds\\monster_roar.wav")
music = pyglet.resource.media(path)

# does work
music = ("monster_roar.wav")
#music.play()

pyglet.resource.ResourceNotFoundException: Resource "C:\Users\Joshua Nixon\Documents\college_work\extended_project\game\new\sounds\monster_roar.wav" was not found on the path. Ensure that the filename has the correct captialisation.

What am i missing?


Solution

  • You should consider using an absolute path instead of a relative path in cases like this. However, your error can likely be fixed with the following:

    Instead of using music = pyglet.resource.media(path)

    ... try using music = pyglet.media.load(path).