Skip to content

Instantly share code, notes, and snippets.

@milangupta4
Last active January 22, 2019 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milangupta4/e171ab540f949d64ab07244236dacfab to your computer and use it in GitHub Desktop.
Save milangupta4/e171ab540f949d64ab07244236dacfab to your computer and use it in GitHub Desktop.
<?php
$vdo_id = '1234567890';
$theme_id = '9ae8bbe8dd964ddc9bdb932cca1cb59a';
// Custom player skins - https://www.vdocipher.com/blog/2018/10/video-player-themes/
include ('./vdo_embed.php');
echo vdo_embed($vdo_id, $theme_id); //Replace 1234567890 with VideoID
?>
<?php
function vdo_embed($video_id, $video_theme = '9ae8bbe8dd964ddc9bdb932cca1cb59a'){
// Edit the API Client Secret Key here
$client_key = 'a1b2c3d4e5f6';
$ttl = 300; // Time to live validity of OTP is set to 300 seconds
$annotate_code = <<< WATERMARK
[{'type':'rtext', 'text':'username', 'alpha':'0.60', 'color':'0xFF0000', 'size':'15', 'interval':'5000'}]
WATERMARK;
// Refer to the blog https://www.vdocipher.com/blog/2014/12/add-text-to-videos-with-watermark/ for more details
// on writing annotation code for watermark
$otp_post_array = array(
"ttl" => $ttl,
"annotate" => $annotate_code
);
$header = array(
'Authorization: Apisecret ' . $client_key,
'Content-Type: application/json',
'Accept: application/json'
);
$otp_post_json = json_encode($otp_post_array);
$url = "https://dev.vdocipher.com/api/videos/$video_id/otp";
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $otp_post_json);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $url);
$otp_response = curl_exec($curl);
curl_close($curl);
$otp_response = json_decode($otp_response);
$OTP = $otp_response->otp;
$playbackInfo = $otp_response->playbackInfo;
$heredoc = <<< EOF
<div id="vdo$OTP" style="width: 1280px; max-width:100%; height:auto;"></div>
<script>
(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){
(v[o].d=v[o].d||[]).push(a); };if(!v[o].l) { v[o].l=1*new Date();
a=i.createElement(d), m=i.getElementsByTagName(d)[0]; a.async=1; a.src=e;
m.parentNode.insertBefore(a,m); }})(window,document,"script",
"https://cdn-gce.vdocipher.com/playerAssets/1.6.10/vdo.js","vdo");
vdo.add({
otp: "$OTP",
playbackInfo: "$playbackInfo",
theme: "$video_theme",
container: document.querySelector( "#vdo$OTP" ),
});
</script>
EOF;
return $heredoc;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment