Forum Discussion

K_Dingman's avatar
K_Dingman
Community Member
6 days ago
Solved

Need audio file to play throughout 2 slides

I have a 2-slide intro with background music that I use for multiple courses. In the previous authoring tool I was using I could place the audio file so that it covered both slides, but I don't see a way to do this in Storyline. I tried adding it as background audio, but I don't see any way to specify that it only play during those 2 slides rather than the whole course. Is there any way to do this?

  • Hi K_Dingman​!

    On the Slide 3, you could add a trigger to pause or stop the Background Audio.

    For a smoother, less abrupt transition, you could use a series of timed triggers to reduce the volume of the Background Audio to zero and then stop it. This would reduce the volume to 90% for instance.

    Or you could let Javascript handle it, but Player.BackgroundAudioVolume can't be set via SetVar() because it's a built-in player property, not a regular Storyline variable.

    To achieve this, you'd need to create a 'bridging' variable, say 'Bgd_Volume' with a starting value of 100, and trigger Player.BackgroundAudioVolume to match any changes to it, like so:

    Then, this JavaScript could gradually reduce the volume over 5 seconds:

    var player = GetPlayer();
    var duration = 5000; // 5 seconds in milliseconds
    var interval = 50;   // Update every 50ms for smooth fade
    var steps = duration / interval;
    var currentVolume = player.GetVar("Bgd_Volume");
    var decrement = currentVolume / steps;
    
    var fade = setInterval(function() {
        currentVolume -= decrement;
    
        if (currentVolume <= 0) {
            currentVolume = 0;
            clearInterval(fade);
        }
    
        player.SetVar("Bgd_Volume", Math.round(currentVolume));
    }, interval);

     


    This trigger would be used to stop your audio when the volume hits 0:

     

    And if the user ever goes back to Slide 1 without restarting the course, and you want the music to play again, these triggers on Slide 1 would reset everything: 

    Hope that helps!

3 Replies

  • Hi K_Dingman​!

    On the Slide 3, you could add a trigger to pause or stop the Background Audio.

    For a smoother, less abrupt transition, you could use a series of timed triggers to reduce the volume of the Background Audio to zero and then stop it. This would reduce the volume to 90% for instance.

    Or you could let Javascript handle it, but Player.BackgroundAudioVolume can't be set via SetVar() because it's a built-in player property, not a regular Storyline variable.

    To achieve this, you'd need to create a 'bridging' variable, say 'Bgd_Volume' with a starting value of 100, and trigger Player.BackgroundAudioVolume to match any changes to it, like so:

    Then, this JavaScript could gradually reduce the volume over 5 seconds:

    var player = GetPlayer();
    var duration = 5000; // 5 seconds in milliseconds
    var interval = 50;   // Update every 50ms for smooth fade
    var steps = duration / interval;
    var currentVolume = player.GetVar("Bgd_Volume");
    var decrement = currentVolume / steps;
    
    var fade = setInterval(function() {
        currentVolume -= decrement;
    
        if (currentVolume <= 0) {
            currentVolume = 0;
            clearInterval(fade);
        }
    
        player.SetVar("Bgd_Volume", Math.round(currentVolume));
    }, interval);

     


    This trigger would be used to stop your audio when the volume hits 0:

     

    And if the user ever goes back to Slide 1 without restarting the course, and you want the music to play again, these triggers on Slide 1 would reset everything: 

    Hope that helps!

  • Yes, it's easy to do, and you're already halfway there, K_Dingman​ .

    Just add a trigger at the end of the timeline of your second slide (or on the click of the “Next” button) that sets the built-in variable “Player.BackgroundAudioVolume” to 0. You won't hear the background audio anymore (until you reset the variable with another trigger if needed).

    Plus : 

    Oh, I hadn't realised that Jonathan_Hill​  had drawn his gun a few seconds before me and hit the target dead centre with a single shot.  😁