How can i access the sound file which is playing in my game and stop it. In upbge 0.3
Sound Actuator + Python
import bge
def main(self):
self.actuators["Sound_Actuator"].stopSound()
AUD Module + Python
import bge, aud
sound_reference = aud.Device().play(aud.Sound("File_Path"))
sound_reference.stop()
1 Like
Yeah, but i want to stop it after a given time and not immediately
Sound Actuator + Python (v2)
- Note: Script requires sound actuator named Sound_Actuator (feel free to rename it).
import bge, aud
def main(self):
if self.actuators["Sound_Actuator"].volume > 0.0:
self.actuators["Sound_Actuator"].volume -= 0.01
else:
self.actuators["Sound_Actuator"].volume = 0.0
self.actuators["Sound_Actuator"].stopSound()
AUD Module + Python (v2)
- Note: Script requires sound actuator named VAR_VOLUME (feel free to rename it).
import bge, aud
PATH_SFX = bge.logic.expandPath(str("//Audio/Space.mp3"))
def main(self):
if self.sensors["Always_Sensor"].status == 1:
global SFX
SFX = aud.Device().play(aud.Sound(PATH_SFX))
if self.owner["VAR_VOLUME"] > 0.0:
self.owner["VAR_VOLUME"] -= 0.01
SFX.volume = self.owner["VAR_VOLUME"]
else:
self.owner["VAR_VOLUME"] = 0.0
SFX.stop()
1 Like
Thank you very much
You’re welcome!
2 Likes