Last active
April 5, 2016 07:16
-
-
Save kuu/3225fcf614a4779923b0 to your computer and use it in GitHub Desktop.
Ooyala Standalone IQ demo (sending analytics signals via a vanilla HTML5 video.)
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"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Ooyala Standalone IQ demo</title> | |
<script src="//analytics.ooyala.com/static/analytics.js"></script> | |
</head> | |
<body> | |
<div> | |
<video src="http://ak.c.ooyala.com/tyMmdsMjE6a4kNpbuyAbhQNPnkqyQCa9/DOcJ-FxaFrRg4gtDEwOmJsOjBrO1Rw6G" width="640" height="360"></video> | |
</div> | |
<button disabled>Play</button> | |
<script> | |
var pCode = 'BtbmUyOlamRiH-S0S-iUeNvf_ghr'; | |
var embedCode = 'tyMmdsMjE6a4kNpbuyAbhQNPnkqyQCa9'; | |
var reporter = new Ooyala.Analytics.Reporter(pCode, { | |
playerName: "vanilla", | |
playerVersion: "0.0.000", | |
contentType: Ooyala.Analytics.MediaContentType.OOYALA_CONTENT // Miss configuration will fall into EXTERNAL_CONTENT. | |
}); | |
reporter.reportPlayerLoad(); | |
reporter.initializeMedia(embedCode); | |
var video = document.querySelector('video'); | |
var button = document.querySelector('button'); | |
var timer, paused = false; | |
video.addEventListener('canplay', function () { | |
console.log('reporter.setMediaDuration(' + video.duration + ');'); | |
reporter.setMediaDuration(video.duration); | |
button.disabled = false; | |
}, false); | |
button.addEventListener('click', function () { | |
if (button.textContent === 'Play') { | |
video.play(); | |
if (!paused) { | |
console.log('reporter.reportPlayRequested();'); | |
reporter.reportPlayRequested(); | |
} | |
button.textContent = 'Pause'; | |
timer = setInterval(onTimer, 1000); | |
} else { | |
video.pause(); | |
button.textContent = 'Play'; | |
clearInterval(timer); | |
} | |
}, false); | |
video.addEventListener('play', function () { | |
if (paused) { | |
console.log('reporter.reportResume();'); | |
reporter.reportResume(); | |
paused = false; | |
} else { | |
console.log('reporter.reportPlaybackStarted();'); | |
reporter.reportPlaybackStarted(); | |
} | |
}, false); | |
video.addEventListener('pause', function () { | |
console.log('reporter.reportPause();'); | |
reporter.reportPause(); | |
paused = true; | |
}, false); | |
video.addEventListener('ended', function () { | |
console.log('reporter.reportComplete();'); | |
reporter.reportComplete(); | |
button.disabled = true; | |
clearInterval(timer); | |
}, false); | |
function onTimer() { | |
console.log('reporter.reportPlayHeadUpdate(' + Math.floor(video.currentTime * 1000) + ');'); | |
reporter.reportPlayHeadUpdate(Math.floor(video.currentTime * 1000)); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment