Forum Archive

sound.Player in scene

Serpensine

Is it possible to get a sound.Player to play in a scene? I have tried the following code in the setup method:

music_player = sound.Player(file_path)
music_player.play()  

But it does not work. sound.play_effect(file_path) does work though, and both of these work when not presented in a scene. Is there a way to make it work?

omz

The problem is probably that music_player is a local variable, and falls out of scope (gets garbage-collected) when the setup method returns. Try self.music_player = ... instead to make it an attribute of the scene.

Serpensine

Ah yes, forgot about that. Works fine now.