In this post I hope to take a step towards making good on a promise I made a few weeks ago: to dive into some of the PHP-related projects on CodePlex that piqued my interest. In particular, I’d planned on diving into the Embedding Silverlight in PHP project, but what I found is that there have been some changes in Microsoft technologies since the release of that project that make it even easier to embed Silverlight in PHP applications. So I’ll stick to the spirit of my promise if not to the letter of it.
I’ll admit in advance that there isn’t much about Silverlight that requires specific PHP knowledge. If you know how to write HTML, then you can follow this post. However, because it is so easy to generate HTML with PHP, you’ll be able to use PHP code like this by the time you finish reading:
displaySilverlightVideo(http://Your_Public_Service_Name.blob.core.windows.net/Container/Default.html, 400, 500 );
And here is the definition of the displaySilverlightVideo function:
function displaySilverlightVideo($source, $height, $width)
echo "<iframe src='";
echo "' frameborder='0' width='$width' height='$height' scrolling='no'></iframe>";
As you can guess from the code, I’m simply uploading a Silverlight-encoded video to my Windows Azure blob storage account and then referencing it from a web page. I’ll walk you through the steps necessary for getting a Silverlight-encoded video into Windows Azure blog storage.
Setting Up Windows Azure Blob Storage
First, you’ll need a Windows Azure subscription. If you don’t already have one, you can create one here: http://www.microsoft.com/windowsazure/offers/. (You’ll need a Windows Live ID to sign up.) I purchased the Windows Azure Platform Introductory Special, which allows me to get started for free as long as keep my usage limited. (This is a limited offer. For complete pricing details, see http://www.microsoft.com/windowsazure/pricing/.) After you purchase your subscription, you will have to activate it before you can begin using it (activation instructions will be provided in an e-mail after signing up).
After you have signed up and logged in, you’ll need to create a New Service…
Select a new Storage Account…
Fill in the service details and click Next…
Finally, enter your public service name, your region, and click Create…
A Primary Access Key and blob service endpoint (in the form of http://your_public_service_name.blob.core.windows.net) will be generated for you. You’ll need these in the next section.
Now you are set to upload Silverlight-encoded videos.
Creating and Uploading Silverlight-Encoded Videos
The Microsoft Expression Encoder 3 (which you can download for free here) will both encode videos and upload them to your blob storage. However, to enable uploading to your blob storage account, you need to install a plug-in. So, after you have installed Expression Encoder 3, download the plug-in from CodePlex here and copy the two .dll files that it contains into the Plugins folder in your Expression Encoder 3 installation directory. (For more detailed instructions, see this excellent blog post by David Sayed: http://blogs.msdn.com/david_sayed/archive/2010/01/07/creating-and-publishing-a-silverlight-video-to-windows-azure.aspx).
Now start Expression Encoder 3 and click on Import to select a video to encode. Next, on the Output tab, select a Silverlight template under Job Output. In the Publish section, choose Windows Azure Blob Storage, check Publish after encode, and fill in your account information. Note that the Container setting can be thought of like a folder name.
And finally, click Encode. And that’s it. Now the URL I used in the PHP code at the beginning of this post makes sense hopefully: http://Your_Public_Service_Name.blob.core.windows.net/Container/Default.html.
Not a PHP-intensive post, but a nice experience for hosting and streaming Silverlight video nonetheless. As always, I’d be interested in what you think of the experience.