Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 153 lines (113 sloc) 6.581 kb
ff70ee5 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
1 <properties
2 pageTitle="How to Deliver Streaming Content from Media Services – Azure"
521811c @Juliako added REST topic
Juliako authored
3 description="Learn how to create a locator that is used to build a streaming URL. Code samples are written in C# and use the Media Services SDK for .NET."
ff70ee5 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
4 authors="juliako"
5 manager="dwrede"
6 editor=""
7 services="media-services"
8 documentationCenter=""/>
a23d8df @v-johugh Removed Chunk References
v-johugh authored
9
ff70ee5 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
10 <tags
11 ms.service="media-services"
12 ms.workload="media"
13 ms.tgt_pltfrm="na"
14 ms.devlang="na"
15 ms.topic="article"
521811c @Juliako added REST topic
Juliako authored
16 ms.date="02/17/2015"
ff70ee5 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
17 ms.author="juliako"/>
fe229ea @mollybostic added tags section
mollybostic authored
18
e7c08d7 @pennij added properties and left-nav
pennij authored
19
be7fd2f @Jemash How to: Deliver streaming content
Jemash authored
20 #How to: Deliver streaming content
5e51258 @migree Refactored the Using Media Services topic
migree authored
21
7e4bf8d @migree I had trouble with my current branch so I wiped it and created a new …
migree authored
22
ace5f40 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
23 This article is part of the [Media Services Video on Demand workflow](media-services-video-on-demand-workflow.md) and [Media Services Live Streaming workflow](media-services-live-streaming-workflow.md) series.
c1e2ff3 @Juliako made more changes
Juliako authored
24
25 ##Overview
26
ace5f40 @sdurandeu Uploaded file articles/media-services-deliver-streaming-content.md
sdurandeu authored
27 You can stream an adaptive bitrate MP4 set by creating an OnDemand streaming locator and building a streaming URL. The [encoding an asset](media-services-encode-asset.md) topic shows how to encode into an adaptive bitrate MP4 set. Before you create a locator you should configure asset delivery policy as described in [this](media-services-dotnet-configure-asset-delivery-policy.md) topic.
5e51258 @migree Refactored the Using Media Services topic
migree authored
28
521811c @Juliako added REST topic
Juliako authored
29 You can also use an OnDemand streaming locator to build URLs that point to MP4 files that can be progressively downloaded.
5e51258 @migree Refactored the Using Media Services topic
migree authored
30
521811c @Juliako added REST topic
Juliako authored
31 This topic shows how to create an OnDemand streaming locator in order to publish your asset and build a Smooth, MPEG DASH, and HLS streaming URLs. It also shows hot to build progressive download URLs.
32
33 ##Create an OnDemand streaming locator
5e51258 @migree Refactored the Using Media Services topic
migree authored
34
521811c @Juliako added REST topic
Juliako authored
35 To create the OnDemand streaming locator and get URLs you need to do the following:
5e51258 @migree Refactored the Using Media Services topic
migree authored
36
521811c @Juliako added REST topic
Juliako authored
37 1. Define an access policy.
38 2. Create an OnDemand streaming locator.
39 3. If you plan to stream, get the streaming manifest file (.ism) in the asset.
40
41 If you plan to progressively download, get the names of MP4 files in the asset.
42 4. Build URLs to the manifest file or MP4 files.
43
44
45 ###Use Media Services .NET SDK
46
47 Build Streaming URLs
48
49 private static void BuildStreamingURLs(IAsset asset)
c1e2ff3 @Juliako made more changes
Juliako authored
50 {
51
52 // Create a 30-day readonly access policy.
521811c @Juliako added REST topic
Juliako authored
53 IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy",
c1e2ff3 @Juliako made more changes
Juliako authored
54 TimeSpan.FromDays(30),
55 AccessPermissions.Read);
56
521811c @Juliako added REST topic
Juliako authored
57 // Create a locator to the streaming content on an origin.
58 ILocator originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset,
c1e2ff3 @Juliako made more changes
Juliako authored
59 policy,
60 DateTime.UtcNow.AddMinutes(-5));
521811c @Juliako added REST topic
Juliako authored
61
c1e2ff3 @Juliako made more changes
Juliako authored
62 // Display some useful values based on the locator.
63 Console.WriteLine("Streaming asset base path on origin: ");
64 Console.WriteLine(originLocator.Path);
65 Console.WriteLine();
521811c @Juliako added REST topic
Juliako authored
66
67 // Get a reference to the streaming manifest file from the
68 // collection of files in the asset.
69 var manifestFile = asset.AssetFiles.Where(f => f.Name.ToLower().
70 EndsWith(".ism")).
71 FirstOrDefault();
c1e2ff3 @Juliako made more changes
Juliako authored
72
73 // Create a full URL to the manifest file. Use this for playback
74 // in streaming media clients.
75 string urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";
521811c @Juliako added REST topic
Juliako authored
76 Console.WriteLine("URL to manifest for client streaming using Smooth Streaming protocol: ");
c1e2ff3 @Juliako made more changes
Juliako authored
77 Console.WriteLine(urlForClientStreaming);
521811c @Juliako added REST topic
Juliako authored
78 Console.WriteLine("URL to manifest for client streaming using HLS protocol: ");
79 Console.WriteLine(urlForClientStreaming + "(format=m3u8-aapl)");
80 Console.WriteLine("URL to manifest for client streaming using MPEG DASH protocol: ");
81 Console.WriteLine(urlForClientStreaming + "(format=mpd-time-csf)");
c1e2ff3 @Juliako made more changes
Juliako authored
82 Console.WriteLine();
521811c @Juliako added REST topic
Juliako authored
83 }
84
85 The code outputs:
86
87 URL to manifest for client streaming using Smooth Streaming protocol:
88 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest
89 URL to manifest for client streaming using HLS protocol:
90 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=m3u8-aapl)
91 URL to manifest for client streaming using MPEG DASH protocol:
92 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny.ism/manifest(format=mpd-time-csf)
93
94
95 Build progressive download URLs
96
97 private static void BuildProgressiveDownloadURLs(IAsset asset)
98 {
99 // Create a 30-day readonly access policy.
100 IAccessPolicy policy = _context.AccessPolicies.Create("Streaming policy",
101 TimeSpan.FromDays(30),
102 AccessPermissions.Read);
c1e2ff3 @Juliako made more changes
Juliako authored
103
521811c @Juliako added REST topic
Juliako authored
104 // Create an OnDemandOrigin locator to the asset.
105 ILocator originLocator = _context.Locators.CreateLocator(LocatorType.OnDemandOrigin, asset,
106 policy,
107 DateTime.UtcNow.AddMinutes(-5));
108
109 // Display some useful values based on the locator.
110 Console.WriteLine("Streaming asset base path on origin: ");
111 Console.WriteLine(originLocator.Path);
112 Console.WriteLine();
113
114 // Get MP4 files.
115 IEnumerable<IAssetFile> mp4AssetFiles = asset
116 .AssetFiles
117 .ToList()
118 .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));
119
120 // Create a full URL to the MP4 files. Use this to progressively download files.
121 foreach (var pd in mp4AssetFiles)
122 Console.WriteLine(originLocator.Path + pd.Name);
c1e2ff3 @Juliako made more changes
Juliako authored
123 }
5e51258 @migree Refactored the Using Media Services topic
migree authored
124
521811c @Juliako added REST topic
Juliako authored
125 The code outputs:
126
127 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_650kbps_AAC_und_ch2_96kbps.mp4
128 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_400kbps_AAC_und_ch2_96kbps.mp4
129 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_3400kbps_AAC_und_ch2_96kbps.mp4
130 http://amstest1.streaming.mediaservices.windows.net/3c5fe676-199c-4620-9b03-ba014900f214/BigBuckBunny_H264_2250kbps_AAC_und_ch2_96kbps.mp4
131
132 . . .
5e51258 @migree Refactored the Using Media Services topic
migree authored
133
521811c @Juliako added REST topic
Juliako authored
134 ###Use Media Services .NET SDK Extensions
5e51258 @migree Refactored the Using Media Services topic
migree authored
135
521811c @Juliako added REST topic
Juliako authored
136 The following code calls .NET SDK extensions methods that create a locator and generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming.
5e51258 @migree Refactored the Using Media Services topic
migree authored
137
521811c @Juliako added REST topic
Juliako authored
138 // Create a loctor.
139 _context.Locators.Create(
140 LocatorType.OnDemandOrigin,
141 inputAsset,
142 AccessPermissions.Read,
143 TimeSpan.FromDays(30));
144
145 // Get the streaming URLs.
146 Uri smoothStreamingUri = inputAsset.GetSmoothStreamingUri();
147 Uri hlsUri = inputAsset.GetHlsUri();
148 Uri mpegDashUri = inputAsset.GetMpegDashUri();
149
150 Console.WriteLine(smoothStreamingUri);
151 Console.WriteLine(hlsUri);
152 Console.WriteLine(mpegDashUri);
Something went wrong with that request. Please try again.