This website uses cookies to enhance your browsing experience. By continuing to use this website, you agree to our use of cookies. Click here to learn more, including how you can manage your cookie preferences.

Back

Create KS protected videos with free preview

Creating protected videos is a request that comes up once in a while in talks and on the forums.
Whether you’d like to sell the videos or allow restricted access for members only, this short tutorial is going to set the ground for it.
The KS Protected Access Control is a way to protect the access to your videos by enforcing the need to pass a KS (Kaltura Session) for the request that serves the video.
It is an advanced method meant to provide the developer of the integrated system means to decide on his side who should have access (valid KS specified) to the videos and who will be denied (no KS provided).
Step 1 – Create an Access Control Profile
Follow these steps:
a. Go to Settings > Access Control > Add Profile.
b. Scroll the window down to “Advanced Security & Pay-per-view”.
c. Check the two boxs (“Secure viewing of this video using server side session” and “Free Preview”).
d. Set the time for the preview period.
Or.. since video is much better than words, watch this short video:

[kaltura-widget uiconfid=”6420041″ entryid=”0_senw31x5″ width=”400″ height=”330″ align=”center” /]

Step 2 – Write the PHP code
We’ll use the PHP API Client library, this of course for the sake of example, you can use any other language for that.
The important part is the definition of the client object, configuring it and creation of the Kaltura Session (KS):
The KS (Kaltura Session) is constructed of a number of elements and must be generated on the system side:

  1. The API secret (KMC>Settings>Integration Settings>User Secret).
  2. The system (your WordPress) user Id.
  3. The Kaltura Session Type (USER in this case, if you use a PHP client library: KalturaSessionType::USER).
  4. Your Kaltura Partner Id.
  5. The Session Expiry in milliseconds.
  6. A special privileges string – this is very important in this case as it is used to determine if the user has access to see the full video or not, it is specified using the string ‘sview:’ with the video entry id concatenated (e.g. ‘sview:1_92cyew21′).
// Your Kaltura credentials
define("PARTNER_ID", "--Set your partner id here--");
define("USER_SECRET", "--Set your API user secret here (KMC>Settings>Integration Settings>User Secret)--");
define("ENTRY_ID", "--Set the entry id of a video with relevant KS access control applied that belong to the above partner id--");
define("UICONF_ID", "--Set the uiconf id of the player you'd like to use. You can find this id in the players list on the Studio tab in KMC--");
// Whatever user id you want to set (This is according to your system deployment):
$user = "SomeoneWeKnow";
//This is the session start function signature: start($secret, $userId = "", $type = 0, $partnerId = -1, $expiry = 86400, $privileges = "")
$session = $client->session->start(USER_SECRET, $user, KalturaSessionType::USER, PARTNER_ID, 86400, 'sview:'.ENTRY_ID);

Note “sview:ENTRY_ID”
To create a KS (Kaltura Session) that will provide access to the video, pass “sview:ENTRY_ID” in the permissions variable when creating a new KS (using the session create function), replacing ENTRY_ID with the id of the video entry to allow access to.
This generated KS should then be rendered to the page if the user has permissions to access the full video.
If the user doesn’t have permissions to access the full video, flashvars shouldn’t render a KS and Kaltura will only stream the preview part of the video as defined in the access control profile.
Then, on the flashvars of the embedded KDP, we’ll provide the created ks as follow:

kWidget.embed( 'playerTarget', {
	'wid' : '_243342',
	'uiconf_id' : '8145862',
	'entry_id' : '1_20x0ca3l',
	'flashvars':{
		'ks': < ?php echo $session; ?>
	}
});

All done. 🙂
Download the sample PHP app here.
If that helped you, or you find a good way to improve it – let us know in the comments / twitter..

Let’s Get Going