Songs "fade" effect in a playList / Song duration

Hi! When you make an audio playList with aud module, you may want to use fade functions from Blender API:

http://www.blender.org/api/blender_python_api_2_74_5/aud.html?highlight=fadein

fadein function is easy to use because we know that we want to apply a fade effect at the beginning of the song. So the start time of fadein is 0.

But when you want to apply a fade effect to the end of the song, you have to tell the fadeout function the moment the fade effect must begin. So you have to know the song duration. As far I know, it’s impossible with aud module. But I found a nice library in one .py file (so you can easily pack it into your .blend): tinytag

With this module, you can easily find the duration of a song:

from tinytag import TinyTag

song = TinyTag.get(songPath)
songDuration = song.duration 

So now, you can use fadeout function:

import aud

device = aud.device()

fac = aud.Factory(songPath)

fac = fac.fadein(0, 5) # Fade effect at the beginning of the song, 5 seconds length
fac = fac.fadeout(songDuration-5, 5) # Fade effect at the end of the song, 5 seconds length

device.play(fac) # play the song!

(In my example, 2/3 songs are already “faded out” :o, but it’s just for example)

Maybe someone knows an easier way to do that, but I share the tip nevertheless…

its perfect thanks youle

ah one thing. when all the songs are played, it doesnt continue playing again. What should we do so that it will be never end?

Hi! http://www.mediafire.com/download/ziytnnwc8gi2rlf/shuffle&fadeIn&Out&loop.rar

myFactoryObject = myFactoryObject.loop(-1) #loop(count)--negative value = infinite

http://www.blender.org/api/blender_python_api_2_74_0/aud.html?highlight=aud#module-aud (aud API)

thanks youle

youle, if i use ogg typed- audio files. The sound can be stretched off or shrinked together ( faster or slower than usual) How can i fix it?