How to: Deliver streaming content
This article is one in a series introducing Windows Azure Media Services programming. The previous topic was How to: Deliver an Asset by Download.
In addition to downloading media content from Media Services, you can use adaptive bitrate streaming to deliver content. For example, you can create a direct URL, called a locator, to streaming content on a Media Services origin server. Client applications such as Microsoft Silverlight can play the streaming content directly from the locator.
The following example shows how to create an origin locator for an output asset produced by a job. The example assumes that you have already obtained a reference to an asset that contains smooth streaming files, and the variable named assetToStream is referenced in the code.
To create an origin locator to streaming content:
- Get a reference to the streaming manifest file (.ism) in the asset
- Define an access policy
- Create the origin locator by calling the CreateLocator method
- Build a URL to the manifest file
The following code shows how to implement the steps:
private static ILocator GetStreamingOriginLocator( string targetAssetID)
// Get a reference to the asset you want to stream.
IAsset assetToStream = GetAsset(targetAssetID);
// Get a reference to the streaming manifest file from the
// collection of files in the asset.
var theManifest =
from f in assetToStream.AssetFiles
// Cast the reference to a true IAssetFile type.
IAssetFile manifestFile = theManifest.First();
IAccessPolicy policy = null;
ILocator originLocator = null;
// Create a 30-day readonly access policy.
policy = _context.AccessPolicies.Create("Streaming policy",
// Create an OnDemandOrigin locator to the asset.
originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, assetToStream,
// Display some useful values based on the locator.
Console.WriteLine("Streaming asset base path on origin: ");
// Create a full URL to the manifest file. Use this for playback
// in streaming media clients.
string urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";
Console.WriteLine("URL to manifest for client streaming: ");
// Display the ID of the origin locator, the access policy, and the asset.
Console.WriteLine("Origin locator Id: " + originLocator.Id);
Console.WriteLine("Access policy Id: " + policy.Id);
Console.WriteLine("Streaming asset Id: " + assetToStream.Id);
// Return the locator.
For more information about delivering assets, see:
So far we have covered delivering media by downloading from Windows Azure Storage and using Smooth Streaming. The next topic How to Deliver HLS content discusses delivering streaming content using Apple HTTP Live Streaming (HLS).