Skip to content

Latest commit

 

History

History
141 lines (104 loc) · 4.55 KB

media-services-dotnet-manage-streaming-endpoints.md

File metadata and controls

141 lines (104 loc) · 4.55 KB
title description services documentationcenter author writer manager editor ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author
Manage streaming endpoints with .NET SDK. | Microsoft Docs
This topic shows how to manage streaming endpoints with the Azure portal.
media-services
Juliako
juliako
cfowler
0da34a97-f36c-48d0-8ea2-ec12584a2215
media-services
media
na
na
article
07/18/2017
juliako

Manage streaming endpoints with .NET SDK

Note

Make sure to review the overview topic. Also, review StreamingEndpoint.

The code in this topic shows how to do the following tasks using the Azure Media Services .NET SDK:

  • Examine the default streaming endpoint.

  • Create/add new streaming endpoint.

    You might want to have multiple streaming endpoints if you plan to have different CDNs or a CDN and direct access.

    [!NOTE] You are only billed when your Streaming Endpoint is in running state.

  • Update the streaming endpoint.

    Make sure to call the Update() function.

  • Delete the streaming endpoint.

    [!NOTE] The default streaming endpoint cannot be deleted.

For information about how to scale the streaming endpoint, see this topic.

Create and configure a Visual Studio project

Set up your development environment and populate the app.config file with connection information, as described in Media Services development with .NET.

Add code that manages streaming endpoints

Replace the code in the Program.cs with the following code:

using System;
using System.Configuration;
using System.Linq;
using Microsoft.WindowsAzure.MediaServices.Client;
using Microsoft.WindowsAzure.MediaServices.Client.Live;

namespace AMSStreamingEndpoint
{
    class Program
    {
	// Read values from the App.config file.
	private static readonly string _AADTenantDomain =
	ConfigurationManager.AppSettings["AADTenantDomain"];
	private static readonly string _RESTAPIEndpoint =
	ConfigurationManager.AppSettings["MediaServiceRESTAPIEndpoint"];

	private static CloudMediaContext _context = null;

	static void Main(string[] args)
	{
	    var tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, AzureEnvironments.AzureCloudEnvironment);
	    var tokenProvider = new AzureAdTokenProvider(tokenCredentials);

	    _context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);

	    var defaultStreamingEndpoint = _context.StreamingEndpoints.Where(s => s.Name.Contains("default")).FirstOrDefault();
	    ExamineStreamingEndpoint(defaultStreamingEndpoint);

	    IStreamingEndpoint newStreamingEndpoint = AddStreamingEndpoint();
	    UpdateStreamingEndpoint(newStreamingEndpoint);
	    DeleteStreamingEndpoint(newStreamingEndpoint);
	}

	static public void ExamineStreamingEndpoint(IStreamingEndpoint streamingEndpoint)
	{
	    Console.WriteLine(streamingEndpoint.Name);
	    Console.WriteLine(streamingEndpoint.StreamingEndpointVersion);
	    Console.WriteLine(streamingEndpoint.FreeTrialEndTime);
	    Console.WriteLine(streamingEndpoint.ScaleUnits);
	    Console.WriteLine(streamingEndpoint.CdnProvider);
	    Console.WriteLine(streamingEndpoint.CdnProfile);
	    Console.WriteLine(streamingEndpoint.CdnEnabled);
	}

	static public IStreamingEndpoint AddStreamingEndpoint()
	{
	    var name = "StreamingEndpoint" + DateTime.UtcNow.ToString("hhmmss");
	    var option = new StreamingEndpointCreationOptions(name, 1)
	    {
		StreamingEndpointVersion = new Version("2.0"),
		CdnEnabled = true,
		CdnProfile = "CdnProfile",
		CdnProvider = CdnProviderType.PremiumVerizon
	    };

	    var streamingEndpoint = _context.StreamingEndpoints.Create(option);

	    return streamingEndpoint;
	}

	static public void UpdateStreamingEndpoint(IStreamingEndpoint streamingEndpoint)
	{
	    if (streamingEndpoint.StreamingEndpointVersion == "1.0")
		streamingEndpoint.StreamingEndpointVersion = "2.0";

	    streamingEndpoint.CdnEnabled = false;
	    streamingEndpoint.Update();
	}

	static public void DeleteStreamingEndpoint(IStreamingEndpoint streamingEndpoint)
	{
	    streamingEndpoint.Delete();
	}
    }
}

Next steps

Review Media Services learning paths.

[!INCLUDE media-services-learning-paths-include]

Provide feedback

[!INCLUDE media-services-user-voice-include]