Files
shaka-player/tutorials/sample5.txt
T
Joey Parrish 139e722ce2 Use https in all tutorials
This is in preparation for a future in which SSL is required by EME.

Change-Id: I82ef395197e27fa5cc9bcaf1afa25e27b9710935
2015-09-03 14:00:08 -07:00

231 lines
7.0 KiB
Plaintext

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TurtleTube - Beta!</title>
<!-- Load the Shaka Player library. -->
<script src="shaka-player.compiled.js"></script>
<style>
body {
background-color: #4a8;
color: #000;
}
h1, h2 {
text-align: center;
}
#thumbContainer {
display: table;
margin: auto;
}
.thumbRow {
display: table-row;
}
.thumbCell {
display: table-cell;
width: 270px;
padding: 10px;
}
.thumbCell img {
width: 270px;
height: 180px;
border: 5px ridge #07a;
margin: 0;
}
#videoOverlay {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 2px;
left: 2px;
right: 2px;
bottom: 2px;
z-index: 1;
overflow: hidden;
text-align: center;
/* Hidden until needed. */
display: none;
}
#closeButton {
position: relative;
margin-top: 10px;
z-index: 2;
}
#vcenterWrapper {
position: absolute;
width: 0;
height: 0;
/* Move the top-left corner of this div to the center. */
top: 50%;
left: 50%;
}
#video {
width: 640px;
height: 480px;
position: relative;
/* Center the video inside the overlay. */
top: -240px;
left: -320px;
}
</style>
</head>
<body>
<h1>TurtleTube!</h1>
<h2>Choose a video:</h2>
<div id="thumbContainer">
<div class="thumbRow">
<div class="thumbCell">
<img id="t1"
src="https://turtle-tube.appspot.com/t/t1/thumb.png"
onclick="onImageClick(this)"><br>
<i>cute green sea turtle in Ko'olina Hawai'i</i><br>
(MP4, WebM)
</div>
<div class="thumbCell">
<img id="t2"
src="https://turtle-tube.appspot.com/t/t2/thumb.png"
onclick="onImageClick(this)"><br>
<i>Endangered Ocean: Sea Turtles</i><br>
(MP4, WebM)
</div>
</div>
<div class="thumbRow">
<div class="thumbCell">
<img id="t3"
src="https://turtle-tube.appspot.com/t/t3/thumb.png"
onclick="onImageClick(this)"><br>
<i>sea turtles exercise: bent arms</i><br>
(WebM only)
</div>
<div class="thumbCell">
<img id="t4"
src="https://turtle-tube.appspot.com/t/t4/thumb.png"
onclick="onImageClick(this)"><br>
<i>sea turtles exercise: straight arms</i><br>
(WebM only)
</div>
</div>
<div class="thumbRow">
<div class="thumbCell">
<img id="t5"
src="https://turtle-tube.appspot.com/t/t5/thumb.png"
onclick="onImageClick(this)"><br>
<i>Using robots to reveal secrets of walking baby sea turtles</i><br>
(MP4, WebM)
</div>
<div class="thumbCell">
<img id="e6"
src="https://turtle-tube.appspot.com/t/e6/thumb.png"
onclick="onImageClick(this)"><br>
<i>kitten vs sea turtle</i><br>
(MP4 only, encrypted)
</div>
</div>
</div>
<div id="videoOverlay">
<div id="vcenterWrapper">
<video id="video"
poster="https://turtle-tube.appspot.com/poster.jpg"
crossorigin="anonymous"
controls autoplay>
Your browser does not support HTML5 video.
</video>
</div>
<button id="closeButton" onclick="closeVideo()">Close Video</button>
</div>
</body>
<script>
var video;
var player;
var estimator;
function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();
// Get the video element.
video = document.getElementById('video');
// Construct the Player to wrap around it.
player = new shaka.player.Player(video);
// Attach the player to the window so that it can be easily debugged.
window.player = player;
// Listen for errors from the Player.
player.addEventListener('error', function(event) {
console.error(event);
});
// Construct a persistent bandwidth estimator to pass to video sources.
// This will allow second and subsequent playbacks to benefit from
// earlier bandwidth estimations and avoid starting at a low-quality
// stream.
estimator = new shaka.util.EWMABandwidthEstimator();
}
/**
* @param {!HTMLImageElement} image
*/
function onImageClick(image) {
// Disregard any bandwidth data older than one hour. The user may have
// changed networks if they are on a laptop or mobile device.
if (estimator.getDataAge() >= 3600) {
estimator = new shaka.util.EWMABandwidthEstimator();
}
// Construct a DashVideoSource to represent the DASH manifest and provide
// a callback to interpret the ContentProtection elements (if any).
var mpdUrl = 'https://turtle-tube.appspot.com/t/' + image.id + '/dash.mpd';
var source = new shaka.player.DashVideoSource(mpdUrl,
interpretContentProtection,
estimator);
// Show the video player overlay.
var overlay = document.getElementById('videoOverlay');
overlay.style.display = 'block';
// Load the source into the Player.
player.load(source);
}
/**
* @param {string} schemeIdUri The ContentProtection's scheme ID URI.
* @param {!Element} contentProtection The ContentProtection element.
* @return {!Array.<shaka.player.DrmInfo.Config>} An array of Config
* objects or null if the element is not understood by this application.
*/
function interpretContentProtection(schemeIdUri, contentProtection) {
// This is the UUID which is used by edash-packager to represent
// Widevine. This is the only scheme we are expecting for this
// application.
if (schemeIdUri == 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed') {
// We will use Widevine's testing license server. In a real app,
// you would run your own front-end service for this.
var licenseServerUrl = 'https://widevine-proxy.appspot.com/proxy';
// The EME key system identifier for Widevine.
var keySystem = 'com.widevine.alpha';
return [{
'keySystem': keySystem,
'licenseServerUrl': licenseServerUrl
}];
}
console.warn('Unrecognized scheme: ' + schemeIdUri);
return null;
}
function closeVideo() {
// Unload the video source.
player.unload();
// Hide the video player overlay.
var overlay = document.getElementById('videoOverlay');
overlay.style.display = 'none';
}
document.addEventListener('DOMContentLoaded', initPlayer);
</script>
</html>