Skip to content

Commit 4991dfe

Browse files
authored
Merge pull request #97576 from Juliako/patch-152
Update upload-index-videos.md
2 parents 86ae04c + 5bb23cd commit 4991dfe

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

articles/media-services/video-indexer/upload-index-videos.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ manager: femila
99
ms.service: media-services
1010
ms.subservice: video-indexer
1111
ms.topic: article
12-
ms.date: 11/29/2019
12+
ms.date: 12/03/2019
1313
ms.author: juliako
1414
---
1515

@@ -116,12 +116,28 @@ If the `videoUrl` is not specified, the Video Indexer expects you to pass the fi
116116

117117
The following C# code snippet demonstrates the usage of all the Video Indexer APIs together.
118118

119+
### Instructions for running this code sample
120+
121+
After copying this code into your development platform you will need to provide two parameters: API Management authentication key and video URL.
122+
123+
* API key – API key is your personal API management subscription key, that will allow you to get an access token in order to perform operations on your Video Indexer account.
124+
125+
To get your API key, go through this flow:
126+
127+
* Navigate to https://api-portal.videoindexer.ai/
128+
* Login
129+
* Go to **Products** -> **Authorization** -> **Authorization subscription**
130+
* Copy the **Primary key**
131+
* Video URL – A URL of the video/audio file to be indexed. The URL must point at a media file (HTML pages are not supported). The file can be protected by an access token provided as part of the URI and the endpoint serving the file must be secured with TLS 1.2 or higher. The URL needs to be encoded.
132+
133+
The result of successfully running the code sample will include an insight widget URL and a player widget URL that will allow you to examine the insights and video uploaded respectively.
134+
135+
119136
```csharp
120137
public async Task Sample()
121138
{
122139
var apiUrl = "https://api.videoindexer.ai";
123-
var location = "westus2";
124-
var apiKey = "...";
140+
var apiKey = "..."; // replace with API key taken from https://aka.ms/viapi
125141
126142
System.Net.ServicePointManager.SecurityProtocol =
127143
System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls12;
@@ -142,15 +158,17 @@ public async Task Sample()
142158
HttpResponseMessage result = await client.GetAsync($"{apiUrl}/auth/trial/Accounts?{queryParams}");
143159
var json = await result.Content.ReadAsStringAsync();
144160
var accounts = JsonConvert.DeserializeObject<AccountContractSlim[]>(json);
145-
// take the relevant account, here we simply take the first
161+
162+
// take the relevant account, here we simply take the first,
163+
// you can also get the account via accounts.First(account => account.Id == <GUID>);
146164
var accountInfo = accounts.First();
147165

148166
// we will use the access token from here on, no need for the apim key
149167
client.DefaultRequestHeaders.Remove("Ocp-Apim-Subscription-Key");
150168

151169
// upload a video
152170
var content = new MultipartFormDataContent();
153-
Debug.WriteLine("Uploading...");
171+
Console.WriteLine("Uploading...");
154172
// get the video from URL
155173
var videoUrl = "VIDEO_URL"; // replace with the video URL
156174
@@ -176,9 +194,9 @@ public async Task Sample()
176194

177195
// get the video ID from the upload result
178196
string videoId = JsonConvert.DeserializeObject<dynamic>(uploadResult)["id"];
179-
Debug.WriteLine("Uploaded");
180-
Debug.WriteLine("Video ID:");
181-
Debug.WriteLine(videoId);
197+
Console.WriteLine("Uploaded");
198+
Console.WriteLine("Video ID:");
199+
Console.WriteLine(videoId);
182200

183201
// wait for the video index to finish
184202
while (true)
@@ -197,16 +215,16 @@ public async Task Sample()
197215

198216
string processingState = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["state"];
199217

200-
Debug.WriteLine("");
201-
Debug.WriteLine("State:");
202-
Debug.WriteLine(processingState);
218+
Console.WriteLine("");
219+
Console.WriteLine("State:");
220+
Console.WriteLine(processingState);
203221

204222
// job is finished
205223
if (processingState != "Uploaded" && processingState != "Processing")
206224
{
207-
Debug.WriteLine("");
208-
Debug.WriteLine("Full JSON:");
209-
Debug.WriteLine(videoGetIndexResult);
225+
Console.WriteLine("");
226+
Console.WriteLine("Full JSON:");
227+
Console.WriteLine(videoGetIndexResult);
210228
break;
211229
}
212230
}
@@ -221,9 +239,9 @@ public async Task Sample()
221239

222240
var searchRequestResult = await client.GetAsync($"{apiUrl}/{accountInfo.Location}/Accounts/{accountInfo.Id}/Videos/Search?{queryParams}");
223241
var searchResult = await searchRequestResult.Content.ReadAsStringAsync();
224-
Debug.WriteLine("");
225-
Debug.WriteLine("Search:");
226-
Debug.WriteLine(searchResult);
242+
Console.WriteLine("");
243+
Console.WriteLine("Search:");
244+
Console.WriteLine(searchResult);
227245

228246
// Generate video access token (used for get widget calls)
229247
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
@@ -241,8 +259,8 @@ public async Task Sample()
241259
});
242260
var insightsWidgetRequestResult = await client.GetAsync($"{apiUrl}/{accountInfo.Location}/Accounts/{accountInfo.Id}/Videos/{videoId}/InsightsWidget?{queryParams}");
243261
var insightsWidgetLink = insightsWidgetRequestResult.Headers.Location;
244-
Debug.WriteLine("Insights Widget url:");
245-
Debug.WriteLine(insightsWidgetLink);
262+
Console.WriteLine("Insights Widget url:");
263+
Console.WriteLine(insightsWidgetLink);
246264

247265
// get player widget url
248266
queryParams = CreateQueryString(
@@ -252,9 +270,16 @@ public async Task Sample()
252270
});
253271
var playerWidgetRequestResult = await client.GetAsync($"{apiUrl}/{accountInfo.Location}/Accounts/{accountInfo.Id}/Videos/{videoId}/PlayerWidget?{queryParams}");
254272
var playerWidgetLink = playerWidgetRequestResult.Headers.Location;
255-
Debug.WriteLine("");
256-
Debug.WriteLine("Player Widget url:");
257-
Debug.WriteLine(playerWidgetLink);
273+
Console.WriteLine("");
274+
Console.WriteLine("Player Widget url:");
275+
Console.WriteLine(playerWidgetLink);
276+
Console.WriteLine("\nPress Enter to exit...");
277+
String line = Console.ReadLine();
278+
if (line == "enter")
279+
{
280+
System.Environment.Exit(0);
281+
}
282+
258283
}
259284

260285
private string CreateQueryString(IDictionary<string, string> parameters)

0 commit comments

Comments
 (0)