Forum Discussion
Dynamically fading audio in SL
ThierryEMMANUEL Every time we come across the same post, something extraordinary comes out of it. Your work motivates me to go even further beyond.
I came up with a modified function that can fade the volume in or out as needed. It works with both background and slide-level audio, as long as only one audio file is playing at a time. Simulating this functionality with multiple audio files is possible, but it would require additional coding to target each audio source individually. This aligns with the original post topic, 'Dynamically fading audio in SL', but I'm not sure whether there are additional audio tracks on the slide that are meant to play simultaneously with the background audio—where only one fades, or vice versa.
However, this is the one where the background audio can be smoothly faded in or out. There is a global function that executes when the timeline starts, which includes both fade-in and fade-out volume functionality. This means you can call the fadeIn() or fadeOut() functions using an "Execute JavaScript" trigger at any point—whether it's after an interaction is completed, an object is clicked, the timeline reaches a certain point, or when a variable changes. You can even pass an argument to the function to control the fade duration — for example, fadeOut(5000) will trigger a 5-second fade out.
At the same time, I've connected and synchronized a slider to the DS volume, allowing its value to be used to trigger other events. In this simple example, the opacity of an image changes dynamically based on the slider’s value, moving back and forth. Of course, this technique can be applied to just about anything.
The slider is optional, the fade-in and fade-out functions work independently, but this example demonstrates how we can now connect and control other properties through volume or slider values.
I've attached the Story file for you to explore.
It's Christmas in August. Thanks, Nedim . I do need more time to explore the different codes. I hope PhilEagles-db80 finds something useful in your answer or mine. If you need my motivation to make you work harder and longer, I'm here whenever you need me 😁.
Related Content
- 2 months ago
- 9 months ago