Skip to content

Instantly share code, notes, and snippets.

@jakob-stoeck
Created February 7, 2017 12:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jakob-stoeck/2c20786efe502ac9a9b161799821d4b4 to your computer and use it in GitHub Desktop.
Save jakob-stoeck/2c20786efe502ac9a9b161799821d4b4 to your computer and use it in GitHub Desktop.
stream tester
<?php
// You can use this file to test different video products in different players
// choose product and options
$product = 'hls'; // hls|stream_packaging|vod
$secure = true;
$staging = false;
$URLonly = false; // true to output only URL, false to output HTML
// no changes required below santa claus - happy holidays 2016
// _...
// o_.-"` `\
// .--. _ `'-._.-'""-; _
// .' \`_\_ {_.-a"a-} _ / \
// _/ .-' '. {c-._o_.){\|` |
// (@`-._ / \{ ^ } \\ _/
// `~\ '-._ /'. } \} .-.
// |>:< '-.__/ '._,} \_/ / ())
// | >:< `'---. ____'-.|(`"`
// \ >:< \\_\\_\ | ;
// \ \\-{}-\/ \
// \ '._\\' /)
// '. /(
// `-._ _____ _ _____ __.'\ \
// / \ / \ / \ \ \
// jgs _.'/^\'._.'/^\'._.'/^\'.__) \
// ,==' `---` '---' '---' )
// `"""""""""""""""""""""""""""""""`
require 'akamai_token_v2.php';
function getStreamURL($product, $secure=true, $staging=false) {
$akamaiKey = '[CHANGEME]';
$products = [
'stream_packaging' => [
'host' => 'sport1_24x7_free-lh.akamaihd.net',
'host_staging' => 'sport1_24x7_free-lh.akamaihd-staging.net',
'host_custom' => 'sport1_24x7_free-lh.streaming.sport1.de',
'path' => '/i/24x7_SPORT1_FREE_1@324937/master.m3u8',
],
'hls' => [
'host' => 'sport1free-i.akamaihd.net',
'host_staging' => 'sport1free-i.akamaihd-staging.net', // only works when setting the Host-header to the non-staging one
'path' => '/hls/live/252861/24x7_Sport1_Free/master.m3u8',
],
'vod' => [
'host' => 'pmds.sport1.de',
'host_staging' => 'pmds.sport1.de.edgekey-staging.net',
'path' => '/p/20160825/0/0_oavju19x_0_3n77b1kf_2.mp4',
],
];
$streamUrl = sprintf('http%s://%s%s', $secure ? 's' : '', $products[$product]['host' . ($staging ? '_staging' : '')], $products[$product]['path']);
if ($product === 'vod') {
return $streamUrl;
}
$c = new Akamai_EdgeAuth_Config();
$c->set_key($akamaiKey);
$c->set_acl('/*');
// $c->set_start_time(strtotime('2016-12-08T00:00:00Z')); // does not work?
$c->set_window(300);
$g = new Akamai_EdgeAuth_Generate();
$token = $g->generate_token($c);
return $streamUrl.'?hdnts='.$token;
}
$url = getStreamURL($product, $secure, $staging);
if ($URLonly) {
die($url.PHP_EOL);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Stream Tester</title>
</head>
<body>
<p><a href="<?php echo $url ?>"><?php echo $url; ?></a></p>
<h2>HTML</h2>
<div id="player-html"><video width="330" controls src="<?php echo $url ?>"></video></div>
<h2>jwplayer</h2>
<div id="player-jw"></div>
<h2>Kolibri</h2>
<div style="width:330px;" id="player-glomex"></div>
<script src="https://content.jwplatform.com/libraries/kGCDasWE.js"></script>
<script src="https://component.p7s1.com/glomex-loader/3.2.0/glomex-loader.js"></script>
<script>
(function insertJwPlayer(videoUrl) {
jwplayer("player-jw").setup({
playlist: [{sources: [{file: videoUrl, type: "hls"}]}],
width: 330,
height: 188,
});
})('<?php echo $url; ?>');
(function insertGlomexPlayer(videoUrl) {
var glomexDomNode = document.getElementById('player-glomex');
// see API docs here: http://docs.p7s1.com/glomex-loader/3.2.0/
glomex.init(glomexDomNode, 'is1hap4j') //config init player ID for sport1.de
.onGlomexPlayer(function(player) {
player.addContent({
id: "12345",
sources: [{
url: videoUrl,
mimetype: "video/mp4"
},
]
});
})
.onPublisherPlayer(function() {
var text = "No Adblocker detected. Place your Videoplayer here.";
glomexDomNode.appendChild(document.createTextNode(text));
glomexDomNode.className = 'publisher-player';
});
})('<?php echo $url; ?>');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment