1

I was making a Tetris-like game, and I would like my friends to try it so I'm going to export it as an .exe file, but I'm playing the track in the background this way:

winsound.PlaySound('C:/Users/User/folder/project/tetris/tetrismusic.wav', 
                   winsound.SND_LOOP + winsound.SND_ASYNC)

I don't know if there is a way to play the file another way that doesn't involve the path. I've also tried:

winsound.Playsound('tetrismusic.wav', winsound.SND_LOOP + winsound.SND_ASYNC))

But it gives out an error saying the file can't be played.

martineau
  • 119,623
  • 25
  • 170
  • 301
Mr. Goose
  • 11
  • 1
  • What tool are you using to convert your script into an `.exe`. You should add it a tag to your question (because it matters). – martineau Feb 03 '22 at 01:50

1 Answers1

1

Try putting a ./ before the filename.

winsound.Playsound('./tetrismusic.wav', winsound.SND_LOOP + winsound.SND_ASYNC))

Or — alternatively — add the SND_FILENAME flag.

winsound.Playsound('tetrismusic.wav', winsound.SND_LOOP + winsound.SND_ASYNC + winsound.SND_FILENAME))

Checking the docs, it seems the Playsound function is assuming that tetrismusic.wav is a sound alias.

Ali Samji
  • 479
  • 2
  • 7