In this section, we’ll return to our podcasting
example. Previously, you’ve used BLOB storage as a place to store your
video and audio podcasts; now you’re going to use BLOB storage as a
mechanism for serving your videos to customers.
Because BLOB storage
provides a URI for any files held in public containers, you could just
make the link available to your customers to download the files offline,
for example, http://storageaccount.blobs.core.windows.net/container/mypodcast.wmv. This probably wouldn’t provide the greatest user experience in the world.
An alternative to downloading
an entire media file is to use streaming. When media is streamed, the
streaming server starts sending a byte stream of the video to the
client. The client media player creates a buffer of the downloaded
bytes, and starts playing the video when the buffer is sufficiently
full. While the user is watching the video from the buffer, the client
continues to download the data in the background.
Media streaming lets the
user start watching the video within seconds, rather than requiring the
user to wait for the entire movie to download. If the user decides to
watch only the first few seconds of the movie, the service provider will
have served up only some of the movie, which results in cheaper
bandwidth bills. Unfortunately, streaming isn’t currently available as
an option in Windows Azure and the Windows Azure BLOB storage service.
If you want to use such a solution, you need to use a third-party
streaming service.
An even better solution is to
use progressive downloading, in which a file is downloaded in small
chunks and is stitched together by the client application. After a few
chunks are downloaded, the client application can start playing the
movie while the rest of the file chunks are downloaded in the
background. Progressive downloading has
the same performance advantages as streaming and provides a similar
user experience. The main difference between progressive downloading and
streaming is that the file being streamed never physically resides on
disk and remains only in memory.
1. Building a Silverlight or WPF video player
By default, Silverlight
supports the ability to progressively download files. In this example,
we’ll tell you how to build a small Silverlight video player that will
allow you to play movies on your web page that are hosted by BLOB
storage. Figure 1
shows a small video player that you’ll build. The video player is
playing a video served directly from BLOB storage using the public URI.
You can build a WPF or Silverlight media player like that shown in figure 10.9 by creating a WPF or Silverlight application and using the following XAML:
<MediaElement x:Name="myVideo" Source="http://storageaccount.blobs.core.windows.net/container/videopodcast01.wmv"
/>
Wow, is that really it? Yup,
that’s how easy it is to create a progressive downloading video player
that shows videos hosted in BLOB storage.
Although Silverlight does
progressively download the video player, the download is performed in a
linear fashion, downloading from a single file, from a single website.
If you have very large files (they’re up to gigabytes), you might want
to use a slightly different technique. For large files, you can download
video much faster if you split up and chunk your files manually (and
eventually split them across multiple servers).