GetDuration

Mar 18, 2024

Hi.
I am trying to use JavaScript to get the duration of a given slide and pass it to Storyline. The SetVar part (where one passes a JavaScript variable to Storyline) works fine, but I cannot seem to obtain the slide duration, although I have seen at least three recommendations that I cannot get to work.

Option 1:
var player = GetPlayer().GetSlide();
//Or var player = GetPlayer();
var duration = player.GetDuration();

Option 2:
var player = GetPlayer();
var timeline = player.GetTimeline();
var duration = timeline.GetDuration();

Option 3:
var slideDuration = GetSlideDuration();

Help! And THANKS!

5 Replies
Sam Hill

Hi Colin, I've never seen these functions before. The API that Storyline provides is very limited. Using the GetPlayer(), you can only use that to GetVar and SetVar.

const player = GetPlayer();

player.SetVar('myvar',true);

player.GetVar('myvar');

In terms of duration, it looks like Storyline provides variables for elapsed time and not duration, for example: Slide.ElapsedTime, Scene.ElapsedTime and Project.ElapsedTime,

Are you able to direct me to where you have scene the examples you provided?

 

 

Sam Hill

Hi Colin, I've made some experiments, and you can get the current slide duration using this:

var currentSlide = DS.appState.windowManager.windows[0].getCurrentSlide();
var slideDuration = currentSlide.attributes.currentTimeline.attributes.duration;
const player = GetPlayer();
player.SetVar('slideDuration',Number(slideDuration));

You would need to have a variable called "slideDuration", type Number, defined in Storyline.

Duration is returned in milliseconds. For example 10 seconds  = 10000.

Disclaimer: This has not been extensively tested. I have tested on a single slide.

 

 

Colin Grant

Sam Hill --

THANK YOU THANK YOU!! You solved my problem!

I tested this in a few different Storyline files and environments, and it seems bulletproof.

As for where I founmd my examples... it's moot now, but they were just results from Googling things like "Storyline Javascript Get Slide Duration functions".

MUCH APPRECIATED!! You are a demigod at least.  :-)