Created
September 27, 2016 18:29
-
-
Save mboles/1d3cad704d89cc635011a65bb711d4e6 to your computer and use it in GitHub Desktop.
Code for multi-session playback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Multiple Session Sample</title> | |
</head> | |
<body> | |
<video id="myPlayerID" | |
style="width: 640px; height: 360px;" | |
data-video-id="4093643993001" | |
data-account="1752604059001" | |
data-player="4bbe4539-ff99-4dfe-a1d3-da554399d064" | |
data-embed="default" | |
class="video-js" | |
controls></video> | |
<script src="//players.brightcove.net/1752604059001/4bbe4539-ff99-4dfe-a1d3-da554399d064_default/index.min.js"></script> | |
<p>video start cookie value = <span id="cookieDisplay1"></span></p> | |
<p>current cookie value = <span id="cookieDisplay2"></span></p> | |
<script type="text/javascript"> | |
var read_cookie = function (key) { | |
var result; | |
return (result = new RegExp('(^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? result[2] : null; | |
} | |
videojs('myPlayerID').ready(function () { | |
var myPlayer = this, | |
videoStart = 0, | |
currentPosition, | |
cookie = read_cookie("BC_position"); | |
if (cookie != null) { | |
videoStart = cookie; | |
} else { | |
videoStart = 0; | |
} | |
document.getElementById("cookieDisplay1").innerHTML = videoStart; | |
myPlayer.on("loadedmetadata", function () { | |
if (videoStart > 0) { | |
myPlayer.currentTime(videoStart); | |
myPlayer.play(); | |
} | |
}); | |
myPlayer.on("timeupdate", function () { | |
currentPosition = myPlayer.currentTime(); | |
if (Math.round(currentPosition) != videoStart) { | |
videoStart = Math.round(currentPosition); | |
document.cookie = "BC_position=" + escape(videoStart) + ";"; | |
document.getElementById("cookieDisplay2").innerHTML = read_cookie("BC_position"); | |
} | |
}); | |
myPlayer.on("ended", function () { | |
videoStart = 0; | |
document.cookie = "BC_position=0;"; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment