Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

비디오 영상 재생 시 본 영상 이전 5초 Pre-Roll과 본 영상 종료 후 Post-Roll 연결과 관련된 샘플입니다. 

HTML
<p align = "middle">
<iframe width="840" height="472" src="https://v.kr.kollus.com/s?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtYyI6W3sibWNrZXkiOiJxTHQ5aE40dSJ9LHsibWNrZXkiOiIzYWYwaEpJNCJ9LHsibWNrZXkiOiJzU0tKaE40eiJ9XSwiY3VpZCI6InRlc3RVc2VyIiwiZXhwdCI6MTg5NTEwMDQwOH0.4QYBH6KjxKySVdE_cL_ta5lD9MKRDvRPg6ZfGWFVOnA&custom_key=497b018267bc529d55ce52c786d8a53e8625f7d611cf316e3b31f05680743d39" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>
</p>


Code Block
languagephp
themeEclipse
titleExample code
collapsetrue
<?php
/**
 * base64_urlencode
 *
 * @param string $str
 * @return string
 */
function base64_urlencode($str) {
    return rtrim(strtr(base64_encode($str), '+/', '-_'), '=');
}

/**
 * jwt_encode
 *
 * @param array $payload
 * @param string $key
 * @return string
 */
function jwt_encode($payload, $key) {
    $jwtHead = base64_urlencode(json_encode(array('typ' => 'JWT', 'alg' => 'HS256')));
    $jsonPayload = base64_urlencode(json_encode($payload));
    $signature = base64_urlencode(hash_hmac('SHA256', $jwtHead . '.' . $jsonPayload, $key, true));

    return $jwtHead . '.' . $jsonPayload . '.' . $signature;
}

$securityKey = 'SECURITY_KEY';
$customKey = 'CUSTOME_KEY';
$mediaContentKeyIntro = 'MEDIA_CONTENT_KEY_INTRO';
$mediaContentKey = 'MEDIA_CONTENT_KEY';
$mediaContentKeyOutro = 'MEDIA_CONTENT_KEY_OUTRO';
$clientUserId = 'CLIENT_USER_ID';
$expireTime =  7200; // 120 min
$mediaItems = array(
    array(
        'media_content_key' => $mediaContentKeyIntro,
    ),

	array(
        'media_content_key' => $mediaContentKey,
    ),

	array(
        'media_content_key' => $mediaContentKeyOutro,
    ),
);

$payload = array(
    'mc' => array(),
    'cuid' => $clientUserId,
    'expt' => time() + $expireTime,
);

foreach ($mediaItems as $mediaItem) {
    $mcClaim = array();
    $mcClaim['mckey'] = $mediaItem['media_content_key'];
    $payload['mc'][] = $mcClaim;
}

$jwtToken = jwt_encode($payload, $securityKey);

$webTokenURL = 'http://v.kr.kollus.com/s?jwt=' . $jwtToken . '&custom_key=' . $customKey;
?>

<!DOCTYPE html>
<html lang="en">
<body>
    <iframe width="840" height="472" src="<?php echo $webTokenURL; ?>" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>
</body>
</html>

Info
titleMore samples

kollus-samples-php

kollus-samples-dotnet

kollus-sample-java

kollus-sample-asp