Esempio n. 1
0
        static void Main(string[] args)
        {
            try
            {
                // Create and cache the Media Services credentials in a static class variable.
                _cachedCredentials = new MediaServicesCredentials(
                    _mediaServicesAccountName,
                    _mediaServicesAccountKey);
                // Used the chached credentials to create CloudMediaContext.
                _context = new CloudMediaContext(_cachedCredentials);

                // Add calls to methods defined in this section.

                IAsset inputAsset =
                    UploadFile(@"D:\MediaServices\dotnetsdk\dotnetsdk\videos\Wildlife.wmv", AssetCreationOptions.None);

                IAsset encodedAsset =
                    EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.None);

                PublishAssetGetURLs(encodedAsset);
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Console.Error.WriteLine(exception.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
        public void ShoudReturnOriginalExceptionIfCannotParseIt()
        {
            var exception       = new Exception("exception message");
            var parsedException = MediaServicesExceptionParser.Parse(exception);

            Assert.AreSame(exception, parsedException);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, AzureEnvironments.AzureCloudEnvironment);
                AzureAdTokenProvider    tokenProvider    = new AzureAdTokenProvider(tokenCredentials);

                _context = new CloudMediaContext(new Uri(_RESTAPIEndpoint), tokenProvider);
                // If you want to secure your high quality input media files with strong encryption at rest on disk,
                // use AssetCreationOptions.StorageEncrypted instead of AssetCreationOptions.None.

                Console.WriteLine("Upload a file.\n");
                IAsset inputAsset =
                    UploadFile(Path.Combine(_mediaFiles, @"BigBuckBunny.mp4"), AssetCreationOptions.None);

                Console.WriteLine("Generate thumbnails and get URLs.\n");

                IAsset thumbnailAsset = GenerateThumbnail(inputAsset, AssetCreationOptions.None);
                PublishAssetGetURLs(thumbnailAsset, false, ".bmp");

                Console.WriteLine("Encode to audio and get an on demand URL.\n");

                IAsset audioOnly = EncodeToAudioOnly(inputAsset, AssetCreationOptions.None);
                PublishAssetGetURLs(audioOnly);

                Console.WriteLine("Encode to adaptive bitraite MP4s and get on demand URLs.\n");

                // If you want to secure your high quality encoded media files with strong encryption at rest on disk,
                // use AssetCreationOptions.StorageEncrypted instead of AssetCreationOptions.None.
                //
                // If your asset is AssetCreationOptions.StorageEncrypted,
                // make sure to call ConfigureClearAssetDeliveryPolicy defined below.

                IAsset encodedAsset =
                    EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.None);

                // If your want to delivery a storage encrypted asset,
                // you must configure the asset’s delivery policy.
                // Before your asset can be streamed,
                // the streaming server removes the storage encryption and
                //streams your content using the specified delivery policy.

                // ConfigureClearAssetDeliveryPolicy(encodedAsset);

                PublishAssetGetURLs(encodedAsset);
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Console.Error.WriteLine(exception.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            try
            {
                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(_AADTenantDomain, new AzureAdClientSymmetricKey(_ClientID, _ClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);

                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);

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

                IMediaProcessor processor = GetLatestMediaProcessorByName("Media Encoder Standard");


                // If you want to secure your high quality input media files with strong encryption at rest on disk,
                // use AssetCreationOptions.StorageEncrypted instead of AssetCreationOptions.None.

                Console.WriteLine("Upload a file.\n");
                //IAsset inputAsset = UploadFile(_mediaFiles, AssetCreationOptions.None);

                // create adaptive bitrate set
                string            assetId = "nb:cid:UUID:59e2bc1d-1726-4645-bece-1b98faca5c8d";
                EncodeJobResponse encJob  = EncodeToAdaptiveBitrateMP4Set(assetId);

                // create associated .vtt file

                // uplaod text file to asset name

                // check status of encode
                CheckJobResponse chkJob;
                do
                {
                    chkJob = CheckJobStatus(encJob.jobId);
                } while (chkJob.isRunning.Equals("true"));
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Console.Error.WriteLine(exception.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
        public void ShoudParseMediaServicesExceptionErrorMessageFromAggregateException()
        {
            var context = this.CreateContext();
            var asset   = context.Assets.Create("EmptyAsset", AssetCreationOptions.None);

            try
            {
                asset.DeleteAsync().Wait();
                asset.DeleteAsync().Wait();
            }
            catch (Exception exception)
            {
                var parsedException = MediaServicesExceptionParser.Parse(exception);

                Assert.IsNotNull(parsedException);
                Assert.AreEqual("Resource Asset not found", parsedException.Message);
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            try
            {
                string mediaServicesAccountName = ConfigurationManager.AppSettings["AccountName"];
                string mediaServicesAccountKey  = ConfigurationManager.AppSettings["AccountKey"];

                CloudMediaContext context = new CloudMediaContext(mediaServicesAccountName, mediaServicesAccountKey);

                VodWorkflowUsingExtensions(context);
                ////VodWorkflow(context);
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Trace.TraceError(exception.Message);
            }
        }
Esempio n. 7
0
        public ActionResult Index()
        {
            try
            {
                _cachedCredentials = new MediaServicesCredentials(
                    _mediaServicesAccountName,
                    _mediaServicesAccountKey);

                _context = new CloudMediaContext(_cachedCredentials);

                var accessToken     = _context.Credentials.AccessToken;
                var tokenExpiration = _context.Credentials.TokenExpiration;

                IAsset inputAsset =
                    UploadFile(@"C:\GitRepo\Azure\media1.mp4", AssetCreationOptions.None);

                IAsset encodedAsset =
                    EncodeToAdaptiveBitrateMP4s(inputAsset, AssetCreationOptions.None);

                PublishAssetGetURLs(encodedAsset);
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Console.Error.WriteLine(exception.Message);
            }
            finally
            {
                Console.ReadLine();
            }


            // SaveTokenDataToExternalStorage(accessToken, tokenExpiration);
            return(View());
        }
Esempio n. 8
0
        private static void Initalize()
        {
            try
            {
                // Create and cache the Media Services credentials in a static class variable.
                _cachedCredentials = new MediaServicesCredentials(
                    _mediaServicesAccountName,
                    _mediaServicesAccountKey);
                // Used the chached credentials to create CloudMediaContext.
                _context = new CloudMediaContext(_cachedCredentials);



                // If you want to secure your high quality input media files with strong encryption at rest on disk,
                // use AssetCreationOptions.StorageEncrypted instead of AssetCreationOptions.None.


                IAsset inputAsset =
                    UploadFile("SET FILE NAME", AssetCreationOptions.None);


                //No config
                var JobState = RunIndexingJob(inputAsset);
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                //Add Output Options Here
                //Response.Write(....);
            }
            finally
            {
                //Do Some Cleanup
            }
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            try
            {
                MediaServicesCredentials credentials = new MediaServicesCredentials(_mediaServicesAccountName, _mediaServicesAccountKey);
                CloudMediaContext        context     = new CloudMediaContext(credentials);

                Console.WriteLine("Creating new asset from local file...");

                // 1. Create a new asset by uploading a mezzanine file from a local path.
                IAsset inputAsset = context.Assets.CreateFromFile(_singleInputMp4Path, AssetCreationOptions.None,
                                                                  (af, p) =>
                {
                    Console.WriteLine("Uploading '{0}' - Progress: {1:0.##}%", af.Name, p.Progress);
                });

                Console.WriteLine("Asset created.");

                // 2. Prepare a job with a single task to transcode the previous mezzanine asset
                // into a multi-bitrate asset.
                IJob job = context.Jobs.CreateWithSingleTask(MediaProcessorNames.WindowsAzureMediaEncoder,
                                                             MediaEncoderTaskPresetStrings.H264AdaptiveBitrateMP4Set720p,
                                                             inputAsset,
                                                             "Sample Adaptive Bitrate MP4",
                                                             AssetCreationOptions.None);

                Console.WriteLine("Submitting transcoding job...");

                // 3. Submit the job and wait until it is completed.
                job.Submit();
                job = job.StartExecutionProgressTask(j => {
                    Console.WriteLine("Job state: {0}", j.State);
                    Console.WriteLine("Job progress: {0:0.##}%", j.GetOverallProgress());
                }, CancellationToken.None).Result;

                Console.WriteLine("Transcoding job finished.");

                IAsset outputAsset = job.OutputMediaAssets[0];

                Console.WriteLine("Publishing output asset...");

                // 4. Publish the output asset by creating an Origin locator for adaptive streaming,
                // and a SAS locator for progressive download.
                context.Locators.Create(LocatorType.OnDemandOrigin, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(30));
                context.Locators.Create(LocatorType.Sas, outputAsset, AccessPermissions.Read, TimeSpan.FromDays(30));

                IEnumerable <IAssetFile> mp4AssetFiles = outputAsset.AssetFiles.ToList()
                                                         .Where(af => af.Name.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase));

                // 5. Generate the Smooth Streaming, HLS and MPEG-DASH URLs for adaptive streaming,
                // and the Progressive Download URL.
                Uri        smoothStreamingUri         = outputAsset.GetSmoothStreamingUri();
                Uri        hlsUri                     = outputAsset.GetHlsUri();
                Uri        mpegDashUri                = outputAsset.GetMpegDashUri();
                List <Uri> mp4ProgressiveDownloadUris = mp4AssetFiles.Select(af => af.GetSasUri()).ToList();

                // 6. Get the asset URLs.
                Console.WriteLine(smoothStreamingUri);
                Console.WriteLine(hlsUri);
                Console.WriteLine(mpegDashUri);
                mp4ProgressiveDownloadUris.ForEach(uri => Console.WriteLine(uri));

                Console.WriteLine("Output asset available for adaptive streaming and progressive download.");

                Console.WriteLine("VOD workflow finished.");
            }
            catch (Exception exception)
            {
                // Parse the XML error message in the Media Services response and create a new
                // exception with its content.
                exception = MediaServicesExceptionParser.Parse(exception);

                Console.Error.WriteLine(exception.Message);
            }
            finally
            {
                Console.ReadLine();
            }
        }
        public void ShoudReturnNullIfOriginalExceptionIsNull()
        {
            var parsedException = MediaServicesExceptionParser.Parse(null);

            Assert.IsNull(parsedException);
        }