Sign in to follow this  
Muzzy A

Getting bad PySound handle with threading - Python

Recommended Posts

I'm playing some music in python, I want the music to fade in.

 

 

 
 
//I have this function to fade it in
def FadeInMusic( speed,song ):
    while( song.volume < 1):
        song.volume += speed
 

musicHandle = FMOD.playSound( musicPath )
musicHandle.volume = 0
 
# Fade the song in at a given speed
t = Thread(target=FadeInMusic, args=(self.musicFadeSpeed,musicHandle,))
t.start()

 

This works sometimes and then sometimes it gives me a PySound error saying that it's an invalid handle to a PySound object

 

What could I do to make sure it's valid?

Share this post


Link to post
Share on other sites

It's not usually safe to have 2 threads accessing the same object like that. So sometimes the system will work, sometimes it won't, and maybe it'll crash.

 

Could you explain exactly what software and libraries you're using? There is probably a built-in system for handling fade ins and outs.

Share this post


Link to post
Share on other sites

I'm using the BigWorld engine. I know the problems that can occur during threading like that. I'm just starting to learn python and i dont know how to handle threads in Python, or data in other threads. I've looked through their documentation and I can't find anything useful.

 

I've googled how to handle threads in python, but all i can find is stuff that is way more complex than it probably needs to be lol.

Share this post


Link to post
Share on other sites

Threads are complex - whether in Python or anywhere else. It's not something you can just Google to learn how to do properly, because it's essentially concurrent computing which often takes weeks of college classes to fully understand.

 

Basically, you shouldn't be using threads for problems like this. You'll need to find their sound documentation and see what facility they provide for fading sounds in and out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this