Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public static string GeneratesEncoder([ActivityTrigger] InitialSetupResult initialSetupResult, TraceWriter log)
IJob job;
// Step 1: Setting up queue, context and endpoint
string endPointAddress = Guid.NewGuid().ToString();
AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_tenantDomain, new AzureAdClientSymmetricKey(_clientId, _clientSecret), AzureEnvironments.AzureCloudEnvironment);
var tokenProvider = new AzureAdTokenProvider(tokenCredentials);
_context = new CloudMediaContext(new Uri(_restApiUrl), tokenProvider);
// Create the queue that will be receiving the notification messages.
_queue = MediaServices.CreateQueue(_storageConnection, endPointAddress);
// Create the notification point that is mapped to the queue.
_notificationEndPoint = _context.NotificationEndPoints.Create(Guid.NewGuid().ToString(), NotificationEndPointType.AzureQueue, endPointAddress);
// Step 2: Creating the encoding job
log.Info("Starting encoding job...");
IMediaProcessor mediaProcessor = MediaServices.GetLatestMediaProcessorByName("Media Encoder Standard", _context);
job = MediaServices.SubmitEncodingJobWithNotificationEndPoint(_context, mediaProcessor.Name, initialSetupResult, _notificationEndPoint);
log.Info("Done. Encoding job successfuly scheduled.");
log.Info("Waiting the encoding process get completed...");
MediaServices.WaitForJobToReachedFinishedState(job.Id, _queue, log);
catch (Exception ex)
return string.Empty;
log.Info("Done. Encoding completed.");
// Step 3: Cleaning up temporary resources
// Step 4: Returns the final result
return job.Id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment