In this article we are going to work with Media Service Account in Azure. Once we create a media service account, we will create a console application in which we will add the operations like creating the media assets dynamically. You can also upload some files to the assets created. We will discuss that here too. I hope you will like this.
Background
A few days back I got a requirement to store some files in the cloud. As you all know, Azure will be the right choice if you talk about cloud services. And I had account with Azure already, so things were pretty easy for me. Thus I decided to create a media service account for this requirement. Here we are going to see how we can create an Azure media service account and how to use the same. Following are the prerequisites.
What is media service account?
- A media service account is a Azure based account which gives you access to cloud based media services in Azure.
- Stores metadata of the media files you create, instead saving the actual media content.
- To work with media service account, you must have an associated storage account.
- While creating a media service account, you can either select the storage account you already have or you can create a new one.
- Since the media service account and storage account is treated separately, the content will be available in your storage account even if you delete your media service account
Please note that your storage account region must be the same as your media service account region.
Prerequisites
- Visual Studio
- Azure account with active subscription
If you are a start up company or you are in thinking to start a one, you can always go for BizSpark(Software and services made for the start ups), to join please check here: How to join bizspark. Or you can always create a free account here.
Things we are going to do
The following are the tasks we are going to do.
Creating an Azure media service accountIf you don’t have an Azure account with active subscription, you must create it first before going to do this task.
- Creating a Console application to use Media service account
- Create an Asset dynamically via console application
- Uploading image to the assets
- Retrieving the items from the Asset
Now we will go and create our media service account.
Steps to create an Azure media service account
To create an Azure media service account, please follow the preceding steps.
Step 1: Login to your Azure Portal (https://portal.azure.com)
Step 2: Click New and select Media + CDN
Step 3: Click on the media service
This will redirect you to old azure portal, If you are not redirected, no worries. It is fine.
Step 4: Give the details.
Here you can select if you have a storage account or a new one will be created for you automatically.
Step 5: Finish
Once you give the needed details, you can click on the tick symbol.
Now we have our storage account and media service account with us. You can always download the sample applications given there. What you need to do all is just select the language you wish and click on the download link. We will create a console application to use this media service account. Sounds cool?
Creating a Console application to use Media service account
To create a console application in Visual Studio click File->New project-> Select language->Select Console Application.
Now go back to your Azure portal and click on Manage Keys at the bottom, copy the MEDIA SERVICE ACCOUNT NAME and MEDIA SERVICE ACCESS KEY (Either primary or secondary). Then you need to add the settings as appSettings in your App.config file as follows.
- <appSettings>
- <add key="MediaServicesAccountName" value="****" />
- <add key="MediaServicesAccountKey" value="***************************" />
- </appSettings>
The next thing you need to do is installing windowsazure.mediaservices from package manager console. For that please go to your package manger console from NuGet Package Manager. And run the below query.
- install-package windowsazure.mediaservices
Now you need to include the preceding namespace to get started with.
- using Microsoft.WindowsAzure.MediaServices.Client;
Now change your Program.cs codes as follows
- using Microsoft.WindowsAzure.MediaServices.Client;
- using System;
- using System.Configuration;
- namespace AzureMediaServiceApp
- {
- class Program
- {#region Constants
- private static string mediaServicesAccountName = ConfigurationManager.AppSettings["MediaServicesAccountName"];
- private static string mediaServicesAccountKey = ConfigurationManager.AppSettings["MediaServicesAccountKey"];#
- endregion
- static void Main(string[] args)
- {
- string input = string.Empty;
- Console.WriteLine("Enter the asset name to be created...");
- input = Console.ReadLine();
- CreateBLOBContainer(input);
- }
- public static string CreateBLOBContainer(string containerName)
- {
- try
- {
- string result = string.Empty;
- CloudMediaContext mediaContext;
- mediaContext = new CloudMediaContext(mediaServicesAccountName, mediaServicesAccountKey);
- IAsset asset = mediaContext.Assets.Create(containerName, AssetCreationOptions.None);
- return asset.Uri.ToString();
- }
- catch (Exception ex)
- {
- return ex.Message;
- }
- }
- }
- }










Sibeesh VenuPosted May 27, 2016, 5:41 AM
Ajay Malik Thanks much
Sibeesh VenuPosted May 27, 2016, 5:41 AM
Michael Griffiths Thanks much
Ajay MalikPosted May 27, 2016, 4:55 AM
nice sharing..
Michael GriffithsPosted May 27, 2016, 3:21 AM
Nice one
Sibeesh VenuPosted May 27, 2016, 12:38 AM
Debasis Saha Thanks a lot
Sibeesh VenuPosted May 27, 2016, 12:38 AM
Kuppurasu Nagaraj Thanks a lot
Debasis SahaPosted May 26, 2016, 3:34 PM
Nice sharing..
Kuppurasu NagarajPosted May 26, 2016, 12:38 PM
Nice Sharing..