0
votes

I am using Azure Media Services and a Silverlight Player to play the streamed url

I am able to ingest, encode the video file as an asset file but when I go play the streamed url I am facing problem.

I use following code to fetch the url...

context = new CloudMediaContext(_accountName, _accountKey);
 IAsset myAsset = GetAsset("UUID:7a32b941-30bd-4c96-bf4e-26df5022eec5");
 var theManifest = from f in myAsset.AssetFiles
 where f.Name.EndsWith(".ism")
 select f;
 var manifestFile = theManifest.First();
 IAccessPolicy streamingPolicy = _context.AccessPolicies.Create("Streaming policy",
 TimeSpan.FromDays(10),
 AccessPermissions.Read);
 ILocator originLocator = _context.Locators.CreateSasLocator(myAsset, streamingPolicy, DateTime.UtcNow.AddMinutes(-500));
 GetAssetSasUrlList(myAsset, originLocator);
 string urlForClientStreaming = originLocator.Path + manifestFile.Name + "/manifest";
 Console.WriteLine("URL to manifest for client streaming: ");
 Console.WriteLine(urlForClientStreaming);

this url comes like --

https://mediasvc06w4dq5k8vd08.blob.core.windows.net/asset-064ed2d5-e42d-4c49-98eb-a712db5c614f?st=2012-12-26T23%3A04%3A22Z&se=2013-01-05T23%3A04%3A22Z&sr=c&si=9350bd2f-ec23-40b2-b27a-248bba01b97e&sig=oGgesnr8mXjCdTM5Dz%2FQpFRBDR0g0%2F60ECoXY14EvsA%3DBigBuckBunny.ism/manifest

Its not working .

When I paste this url on browser directly ,I get following error

AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:154422cf-822e-4bbc-af2a-fa69273dfb89 Time:2012-12-27T08:57:30.9509847ZSignature fields not well formed.

But if I go and publish asset from portal( www.manage.windowsazure.com )-- I get like following url on protal..

http://mediaervices.origin.mediaservices.windows.net/5edbeae7-c3e6-45c5-bc5c-70f46b526cb5/BigBuckBunny.ism/Manifest

And it works with my silverlight player..

Now problem is that I am not getting url which starts with http from code and the url starting with https is not working with my player.

I guessed that its security issue and tried to host my player in winows azure and tried to player there but no success.

1

1 Answers

3
votes

No, not a security issue. You are requesting a SAS url for a Smooth asset, you need an Origin URL. The correct code snippet is here, on my blog: http://blog-ndrouin.azurewebsites.net/?p=1931

Specifically:

    private static string GetStreamingUrl(CloudMediaContext context, string outputAssetId)
    {
        var daysForWhichStreamingUrlIsActive = 365;

        var outputAsset = context.Assets.Where(a => a.Id == outputAssetId).FirstOrDefault();

        var accessPolicy = context.AccessPolicies.Create(outputAsset.Name, TimeSpan.FromDays(daysForWhichStreamingUrlIsActive), AccessPermissions.Read | AccessPermissions.List);

        var assetFiles = outputAsset.AssetFiles.ToList();

        var assetFile = assetFiles.Where(f => f.Name.ToLower().EndsWith("m3u8-aapl.ism")).FirstOrDefault();
        if (assetFile != null)
        {
            var locator = context.Locators.CreateLocator(LocatorType.OnDemandOrigin, outputAsset, accessPolicy);

            Uri hlsUri = new Uri(locator.Path + assetFile.Name + "/manifest(format=m3u8-aapl)");
            return hlsUri.ToString();
        }

        assetFile = assetFiles.Where(f => f.Name.ToLower().EndsWith(".ism")).FirstOrDefault();
        if (assetFile != null)
        {
            var locator = context.Locators.CreateLocator(LocatorType.OnDemandOrigin, outputAsset, accessPolicy);
            Uri smoothUri = new Uri(locator.Path + assetFile.Name + "/manifest");
            return smoothUri.ToString();
        }

        assetFile = assetFiles.Where(f => f.Name.ToLower().EndsWith(".mp4")).FirstOrDefault();
        if (assetFile != null)
        {
            var locator = context.Locators.CreateLocator(LocatorType.Sas, outputAsset, accessPolicy);
            var mp4Uri = new UriBuilder(locator.Path);
            mp4Uri.Path += "/" + assetFile.Name;
            return mp4Uri.ToString();
        }
        return string.Empty;
    }