<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Viddler Developers &#187; recording</title>
	<atom:link href="http://developers.viddler.com/tag/recording/feed/" rel="self" type="application/rss+xml" />
	<link>http://developers.viddler.com</link>
	<description>Testing tomorrow's video platform, today.</description>
	<lastBuildDate>Wed, 09 Sep 2009 04:27:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting Started With phpViddler, Part 3: Recording videos with a webcam</title>
		<link>http://developers.viddler.com/2008/04/22/phpviddler-part-3-recording-videos/</link>
		<comments>http://developers.viddler.com/2008/04/22/phpviddler-part-3-recording-videos/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 09:16:04 +0000</pubDate>
		<dc:creator>Kyle Slattery</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[phpViddler]]></category>
		<category><![CDATA[recording]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://lab.viddler.com/?p=18</guid>
		<description><![CDATA[One of the great aspects of Viddler&#8217;s API is the ability to embed our webcam recorder right into your site.  With only a few lines of code, your users will be able to record video using any camera attached to their computer, and it&#8217;s automatically uploaded to Viddler and encoded.  Let&#8217;s dive right [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great aspects of Viddler&#8217;s API is the ability to embed our webcam recorder right into your site.  With only a few lines of code, your users will be able to record video using any camera attached to their computer, and it&#8217;s automatically uploaded to Viddler and encoded.  Let&#8217;s dive right in!</p>
<p>First off, if you haven&#8217;t checked out <a href="http://lab.viddler.com/2008/04/20/phpviddler-part-1-listing-video/">part one</a> and <a href="http://lab.viddler.com/2008/04/20/getting-started-with-phpviddler-part-2-user-authentication-and-sessions/">part two</a> of the phpViddler series, you&#8217;ll want to do that first, as some of that code will be necessary for recording.<br />
<span id="more-18"></span><br />
As explained on <a href="http://wiki.developers.viddler.com/index.php/Record_With_Webcam_API">the wiki page</a>, there are 2 steps to embedding the video recorder on your site:</p>
<ol>
<li>Get a record_token using either <a href="http://wiki.developers.viddler.com/index.php/Viddler.users.auth">Viddler.users.auth</a> with get_record_token set to &#8220;1&#8243; or <a href="http://wiki.developers.viddler.com/index.php/Viddler.videos.getRecordToken">Viddler.videos.getRecordToken</a>.</li>
<li>Use the returned record_token to embed the recorder on your site.</li>
</ol>
<h3>Getting A Record Token</h3>
<p>In order to embed the video recorder, you&#8217;ll need to pass a &#8220;record token,&#8221; which is a one-time use key that allows the user to record a video.  There are two ways to get the record token, so I&#8217;ll go through both.</p>
<h4>During User Authentication</h4>
<p>When you use the <code>user_authenticate()</code> function (<a href="http://lab.viddler.com/2008/04/20/getting-started-with-phpviddler-part-2-user-authentication-and-sessions/">covered in part 2</a>), you can pass a third parameter to return a record token, which is then returned along with the sessionid:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$sessionResponse</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$viddler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$recordToken</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$sessionResponse</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'auth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'record_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>After Authentication</h4>
<p>If you already have a valid sessionID, but you haven&#8217;t yet generated a record token, you can use the <code>video_getrecordtoken()</code> method, which takes a sessionID as a parameter.  Here&#8217;s how you&#8217;d use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$recordToken</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$viddler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">video_getrecordtoken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sessionID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Personally, I prefer grabbing the token during authentication, since it cuts down on the number of API calls I have to make, but it really depends on the situation.</p>
<p><strong>Note:</strong> While sessionIDs expire, as you no doubt learned in part two, record tokens <em>never expire</em> but can only be used once.  So if you generate a record token for the user when they login, you can keep this token until it is used for as long as you&#8217;d like.</p>
<h3>Embedding the Video Recorder</h3>
<p>Now that you have your record token, it&#8217;s time to embed the video recorder.  Thankfully, phpViddler makes it easy again with the <code>video_getRecordEmbed()</code> function.  To use it, just pass it a record token:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$viddler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">video_getRecordEmbed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recordToken</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And with that, your users are ready to record videos right from your site!</p>
<h4>Knowing When Recording is Finished</h4>
<p>After your user successfully records a video, you&#8217;ll likely want to send them to a new page, or call some other action.  Luckily, the video recorder calls a javascript function, <code>recordDone()</code> when it&#8217;s finished.  To implement this, you&#8217;ll have to add something like the following to your record page:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> recordDone<span style="color: #009900;">&#40;</span>username<span style="color: #339933;">,</span> user_video_number<span style="color: #339933;">,</span> video_id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Alert the user that recording is finished</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Thanks '</span><span style="color: #339933;">;</span> <span style="color: #339933;">+</span> username <span style="color: #339933;">+</span> <span style="color: #3366CC;">', you'</span>ve recorded video #<span style="color: #3366CC;">' + user_video_number + '</span> <span style="color: #000066; font-weight: bold;">with</span> id <span style="color: #3366CC;">' + video_id);
&nbsp;
  // Send user to new page
  top.location('</span>http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//newpage.com');</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>As you can see, <code>recordDone()</code> receives 3 arguments, which you can use however you&#8217;d like:</p>
<ul>
<li><strong>username</strong>: The user who recorded a video</li>
<li><strong>user_video_number</strong>: The number that appears in the video&#8217;s Viddler URL, e.g. http://www.viddler.com/explore/kyleslat/videos/24/</li>
<li><strong>video_id</strong>: The video&#8217;s unique ID, which can be used to embed the player.</li>
</ul>
<p>So, there you have it, with a few simple lines of code, users are now able to record video directly from your site!  Next up, we&#8217;ll be tackling uploading videos, so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.viddler.com/2008/04/22/phpviddler-part-3-recording-videos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
