Think 80’s! Guess the song (JavaScript and Storyline)!

In a previous post, I showed how to add a YouTube video in Storyline via YouTube iframe API. This is a simple implementation of the same concept WITH a TWIST.

One clip is from YouTube, the other is local. You can control the YouTube video from inside Storyline but also detect when it’s stopped/paused or when it ends. This allows you to sync it with other things like another video. Besides, this example will challenge you visual imagination…


SONG #1:

SONG #2:


Watch TruScribe in action, and try to guess the song from the 80’s… More songs are on the way.

How does Storyline know when you pause the YouTube video?

The YouTube iFrame API calls this function when the player’s state changes.
When the video is over you pause, it calls this function. It also sends some info, called “event”.
This helps you figure out what state has changed.

Since this is in an iframe, and Storyline has the “parent frame,”
you can call Storyline’s /story_content/user.js funcions by referring to them as parent.WhatEverYourFunctionIs.

See full example, source and comments in my previous post.

var done = 0;
var paused = 0;

function onPlayerStateChange(event) {

if ( == YT.PlayerState.ENDED && !done) {
done = 1;

if ( == YT.PlayerState.PAUSED && !paused) {
paused = 1;
timepaused=Math.round(player.getCurrentTime()); // This is to save the timestamp when pause happened.

if ( == YT.PlayerState.PLAYING && paused) {
paused = 0;
timerest+=(Math.round(player.getCurrentTime()-timepaused)); // This is to figure out how long it was paused. You only need this if it matters how long you pause the video.




Leave a Reply

Your email address will not be published. Required fields are marked *