0

In my game, I'm using the Playsound Python module in Python version 2.7. I can get a sound to play using the commands shown in the documentation. But I can't find how to turn the sound off.

from playsound import playsound # Imports Library To Play Sound

def playy():
    playsound('music.mp3')

T = Thread(target=playy)
T.start()

The T is part of multithreading so the program plays music while the game runs. The playsound function above plays the sound I want but it won't turn off. I've tried many things like playsound = False. But I can't seem to turn it off.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • Where is `playsound` coming from? There's nothing by that name in `pysound`. – Mark Ransom Nov 14 '19 at 23:55
  • its an import from a library. –  Nov 15 '19 at 00:02
  • Yes but which one? Add the `import` statement to your question so there's no ambiguity. – Mark Ransom Nov 15 '19 at 00:07
  • ok, just did. ty –  Nov 15 '19 at 00:15
  • From the source for the [`playsound`](https://pypi.org/project/playsound/) module, it doesn't look like it supports turning off the sound. Since it's Pure Python, you could theoretically modify it and add that capability. It plays the actually sounds differently on various platforms, providing support for all of them might be a quite a bit of work… – martineau Nov 15 '19 at 00:52
  • 1
    The problem you are having is strongly attributed to multithreading. In python you cant kill a thread easily. Research on how to kill a thread. – Anil_M Nov 26 '19 at 08:12

0 Answers0